Skip to content

Commit a0ceaf2

Browse files
authored
ref: Check for node-env first and return more accurate global object (#1597)
1 parent 11fa899 commit a0ceaf2

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

packages/utils/src/misc.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
import { SentryEvent } from '@sentry/types';
22
import { isString } from './is';
33

4+
/**
5+
* Checks whether we're in the Node.js or Browser environment
6+
*
7+
* @returns Answer to given question
8+
*/
9+
export function isNodeEnv(): boolean {
10+
// tslint:disable:strict-type-predicates
11+
return Object.prototype.toString.call(typeof process !== 'undefined' ? process : 0) === '[object process]';
12+
}
13+
414
/**
515
* Safely get global scope object
616
*
717
* @returns Global scope object
818
*/
919
// tslint:disable:strict-type-predicates
1020
export function getGlobalObject(): Window | NodeJS.Global | {} {
11-
return typeof window !== 'undefined'
12-
? window
13-
: typeof global !== 'undefined'
14-
? global
15-
: typeof self !== 'undefined'
16-
? self
17-
: {};
21+
return isNodeEnv() ? global : typeof window !== 'undefined' ? window : typeof self !== 'undefined' ? self : {};
1822
}
1923
// tslint:enable:strict-type-predicates
2024

0 commit comments

Comments
 (0)