From 4789457558e50bfc36a55ad331ee76a8e35886f3 Mon Sep 17 00:00:00 2001 From: Mertcan Mermerkaya Date: Thu, 9 May 2019 12:48:52 +0100 Subject: [PATCH 1/2] Fix browser detection Web Workers are browser too. --- packages/util/src/environment.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/util/src/environment.ts b/packages/util/src/environment.ts index 321b593b1b7..0bee7a4df79 100644 --- a/packages/util/src/environment.ts +++ b/packages/util/src/environment.ts @@ -68,7 +68,7 @@ export function isNode(): boolean { * Detect Browser Environment */ export function isBrowser(): boolean { - return typeof window !== 'undefined'; + return typeof self === 'object' && self.self === self; } /** From 647def182878fb30d621c325c29046e79d0c20a5 Mon Sep 17 00:00:00 2001 From: Mertcan Mermerkaya Date: Thu, 9 May 2019 13:04:59 +0100 Subject: [PATCH 2/2] Remove redundant type annotations, fix comments --- packages/util/src/environment.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/util/src/environment.ts b/packages/util/src/environment.ts index 0bee7a4df79..0e33b246db7 100644 --- a/packages/util/src/environment.ts +++ b/packages/util/src/environment.ts @@ -19,7 +19,7 @@ import { CONSTANTS } from './constants'; /** * Returns navigator.userAgent string or '' if it's not defined. - * @return {string} user agent string + * @return user agent string */ export function getUA(): string { if ( @@ -35,10 +35,9 @@ export function getUA(): string { /** * Detect Cordova / PhoneGap / Ionic frameworks on a mobile device. * - * Deliberately does not rely on checking `file://` URLs (as this fails PhoneGap in the Ripple emulator) nor - * Cordova `onDeviceReady`, which would normally wait for a callback. - * - * @return {boolean} isMobileCordova + * Deliberately does not rely on checking `file://` URLs (as this fails PhoneGap + * in the Ripple emulator) nor Cordova `onDeviceReady`, which would normally + * wait for a callback. */ export function isMobileCordova(): boolean { return ( @@ -51,9 +50,9 @@ export function isMobileCordova(): boolean { /** * Detect Node.js. * - * @return {boolean} True if Node.js environment is detected. - * Node detection logic from: https://github.com/iliakan/detect-node/ + * @return true if Node.js environment is detected. */ +// Node detection logic from: https://github.com/iliakan/detect-node/ export function isNode(): boolean { try { return ( @@ -74,7 +73,7 @@ export function isBrowser(): boolean { /** * Detect React Native. * - * @return {boolean} True if ReactNative environment is detected. + * @return true if ReactNative environment is detected. */ export function isReactNative(): boolean { return ( @@ -85,7 +84,7 @@ export function isReactNative(): boolean { /** * Detect whether the current SDK build is the Node version. * - * @return {boolean} True if it's the Node SDK build. + * @return true if it's the Node SDK build. */ export function isNodeSdk(): boolean { return CONSTANTS.NODE_CLIENT === true || CONSTANTS.NODE_ADMIN === true;