How to use the @aws-amplify/core.JS.browserOrNode function in @aws-amplify/core

To help you get started, we’ve selected a few @aws-amplify/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws-amplify / amplify-js / packages / auth / src / urlListener.ts View on Github external
export default callback => {
    if (JS.browserOrNode().isBrowser && window.location) {
        const url = window.location.href;

        callback({ url });
    } else if (JS.browserOrNode().isNode) {
        // continue building on ssr
        () => {}; // noop
    } else {
        throw new Error('Not supported');
    }
};
github aws-amplify / amplify-js / packages / analytics / src / vendor / dom-utils / matches.ts View on Github external
/**
 * Copyright (c) 2017, Philip Walton 
 */

import { JS } from '@aws-amplify/core';

const proto =
	JS.browserOrNode().isBrowser && window['Element']
		? window['Element'].prototype
		: null;

const nativeMatches = proto
	? proto.matches ||
	  // @ts-ignore
	  proto.matchesSelector ||
	  // @ts-ignore
	  proto.webkitMatchesSelector ||
	  // @ts-ignore
	  proto.mozMatchesSelector ||
	  // @ts-ignore
	  proto.msMatchesSelector ||
	  // @ts-ignore
	  proto.oMatchesSelector
	: null;
github aws-amplify / amplify-js / packages / auth / src / urlListener.ts View on Github external
export default callback => {
    if (JS.browserOrNode().isBrowser && window.location) {
        const url = window.location.href;

        callback({ url });
    } else if (JS.browserOrNode().isNode) {
        // continue building on ssr
        () => {}; // noop
    } else {
        throw new Error('Not supported');
    }
};
github aws-amplify / amplify-js / packages / analytics / src / trackers / SessionTracker.ts View on Github external
private _envCheck() {
		if (!JS.browserOrNode().isBrowser) {
			return false;
		}

		if (!document || !document.addEventListener) {
			logger.debug('not in the supported web environment');
			return false;
		}

		if (typeof document.hidden !== 'undefined') {
			this._hidden = 'hidden';
			this._visibilityChange = 'visibilitychange';
		} else if (typeof document['msHidden'] !== 'undefined') {
			this._hidden = 'msHidden';
			this._visibilityChange = 'msvisibilitychange';
		} else if (typeof document['webkitHidden'] !== 'undefined') {
			this._hidden = 'webkitHidden';
github aws-amplify / amplify-js / packages / analytics / src / trackers / PageViewTracker.ts View on Github external
const getUrl = () => {
    if (!JS.browserOrNode().isBrowser) return '';
    else return window.location.origin + window.location.pathname;
};
github aws-amplify / amplify-js / packages / analytics / src / trackers / EventTracker.ts View on Github external
constructor(tracker, opts) {
		if (!JS.browserOrNode().isBrowser || !window.addEventListener) {
			logger.debug('not in the supported web environment');
			return;
		}

		this._config = Object.assign({}, defaultOpts, opts);
		this._tracker = tracker;
		this._delegates = {};
		this._trackFunc = this._trackFunc.bind(this);

		logger.debug('initialize pageview tracker with opts', this._config);

		this.configure(this._config);
	}
github aws-amplify / amplify-js / packages / analytics / src / trackers / PageViewTracker.ts View on Github external
private async _pageViewTrackDefault() {
        if (!JS.browserOrNode().isBrowser || !window.addEventListener || !window.sessionStorage) {
            logger.debug('not in the supported web enviroment');
            return;
        }
        const url = this._config.getUrl();
        const customAttrs = typeof this._config.attributes === 'function'? 
            await this._config.attributes() : this._config.attributes;
        const attributes = Object.assign(
            {
                url
            },
            customAttrs
        );

        if (this._config.enable && !this._isSameUrl()) {
            this._tracker(
                {
github aws-amplify / amplify-js / packages / analytics / src / trackers / PageViewTracker.ts View on Github external
private _pageViewTrackSPA() {
        if (!JS.browserOrNode().isBrowser || !window.addEventListener || !history.pushState) {
            logger.debug('not in the supported web enviroment');
            return;
        }

        if (this._config.enable && !this._hasEnabled) {
            MethodEmbed.add(history, 'pushState', this._trackFunc);
            MethodEmbed.add(history, 'replaceState', this._trackFunc);
            window.addEventListener('popstate', this._trackFunc);
            this._trackFunc();
            this._hasEnabled = true;
        } else {
            MethodEmbed.remove(history, 'pushState');
            MethodEmbed.remove(history, 'replaceState');
            window.removeEventListener('popstate', this._trackFunc);
            this._hasEnabled = false;
        }