Skip to content

Commit

Permalink
fix(core): fix ReferenceError: navigator is not defined for custom …
Browse files Browse the repository at this point in the history
…environments; (#6567)
  • Loading branch information
DigitalBrainJS authored Aug 23, 2024
1 parent 550d885 commit fed1a4b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/helpers/isURLSameOrigin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default platform.hasStandardBrowserEnv ?
// Standard browser envs have full support of the APIs needed to test
// whether the request URL is of the same origin as current location.
(function standardBrowserEnv() {
const msie = /(msie|trident)/i.test(navigator.userAgent);
const msie = platform.navigator && /(msie|trident)/i.test(platform.navigator.userAgent);
const urlParsingNode = document.createElement('a');
let originURL;

Expand Down
9 changes: 5 additions & 4 deletions lib/platform/common/utils.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';

const _navigator = typeof navigator === 'object' && navigator || undefined;

/**
* Determine if we're running in a standard browser environment
*
Expand All @@ -17,10 +19,8 @@ const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'unde
*
* @returns {boolean}
*/
const hasStandardBrowserEnv = (
(product) => {
return hasBrowserEnv && ['ReactNative', 'NativeScript', 'NS'].indexOf(product) < 0
})(typeof navigator !== 'undefined' && navigator.product);
const hasStandardBrowserEnv = hasBrowserEnv &&
(!_navigator || ['ReactNative', 'NativeScript', 'NS'].indexOf(_navigator.product) < 0);

/**
* Determine if we're running in a standard browser webWorker environment
Expand All @@ -46,5 +46,6 @@ export {
hasBrowserEnv,
hasStandardBrowserWebWorkerEnv,
hasStandardBrowserEnv,
_navigator as navigator,
origin
}

0 comments on commit fed1a4b

Please sign in to comment.