Skip to content

Commit 46ba69a

Browse files
authored
Fix browser detection (#1773)
Web Workers are browser too.
1 parent 9a49973 commit 46ba69a

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

packages/util/src/environment.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { CONSTANTS } from './constants';
1919

2020
/**
2121
* Returns navigator.userAgent string or '' if it's not defined.
22-
* @return {string} user agent string
22+
* @return user agent string
2323
*/
2424
export function getUA(): string {
2525
if (
@@ -35,10 +35,9 @@ export function getUA(): string {
3535
/**
3636
* Detect Cordova / PhoneGap / Ionic frameworks on a mobile device.
3737
*
38-
* Deliberately does not rely on checking `file://` URLs (as this fails PhoneGap in the Ripple emulator) nor
39-
* Cordova `onDeviceReady`, which would normally wait for a callback.
40-
*
41-
* @return {boolean} isMobileCordova
38+
* Deliberately does not rely on checking `file://` URLs (as this fails PhoneGap
39+
* in the Ripple emulator) nor Cordova `onDeviceReady`, which would normally
40+
* wait for a callback.
4241
*/
4342
export function isMobileCordova(): boolean {
4443
return (
@@ -51,9 +50,9 @@ export function isMobileCordova(): boolean {
5150
/**
5251
* Detect Node.js.
5352
*
54-
* @return {boolean} True if Node.js environment is detected.
55-
* Node detection logic from: https://github.com/iliakan/detect-node/
53+
* @return true if Node.js environment is detected.
5654
*/
55+
// Node detection logic from: https://github.com/iliakan/detect-node/
5756
export function isNode(): boolean {
5857
try {
5958
return (
@@ -68,13 +67,13 @@ export function isNode(): boolean {
6867
* Detect Browser Environment
6968
*/
7069
export function isBrowser(): boolean {
71-
return typeof window !== 'undefined';
70+
return typeof self === 'object' && self.self === self;
7271
}
7372

7473
/**
7574
* Detect React Native.
7675
*
77-
* @return {boolean} True if ReactNative environment is detected.
76+
* @return true if ReactNative environment is detected.
7877
*/
7978
export function isReactNative(): boolean {
8079
return (
@@ -85,7 +84,7 @@ export function isReactNative(): boolean {
8584
/**
8685
* Detect whether the current SDK build is the Node version.
8786
*
88-
* @return {boolean} True if it's the Node SDK build.
87+
* @return true if it's the Node SDK build.
8988
*/
9089
export function isNodeSdk(): boolean {
9190
return CONSTANTS.NODE_CLIENT === true || CONSTANTS.NODE_ADMIN === true;

0 commit comments

Comments
 (0)