mirror of
https://github.com/tenrok/axios.git
synced 2026-06-20 20:00:40 +03:00
fix(core): fix ReferenceError: navigator is not defined for custom environments; (#6567)
This commit is contained in:
@@ -8,7 +8,7 @@ export default platform.hasStandardBrowserEnv ?
|
|||||||
// Standard browser envs have full support of the APIs needed to test
|
// Standard browser envs have full support of the APIs needed to test
|
||||||
// whether the request URL is of the same origin as current location.
|
// whether the request URL is of the same origin as current location.
|
||||||
(function standardBrowserEnv() {
|
(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');
|
const urlParsingNode = document.createElement('a');
|
||||||
let originURL;
|
let originURL;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';
|
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
|
* Determine if we're running in a standard browser environment
|
||||||
*
|
*
|
||||||
@@ -17,10 +19,8 @@ const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'unde
|
|||||||
*
|
*
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
const hasStandardBrowserEnv = (
|
const hasStandardBrowserEnv = hasBrowserEnv &&
|
||||||
(product) => {
|
(!_navigator || ['ReactNative', 'NativeScript', 'NS'].indexOf(_navigator.product) < 0);
|
||||||
return hasBrowserEnv && ['ReactNative', 'NativeScript', 'NS'].indexOf(product) < 0
|
|
||||||
})(typeof navigator !== 'undefined' && navigator.product);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determine if we're running in a standard browser webWorker environment
|
* Determine if we're running in a standard browser webWorker environment
|
||||||
@@ -46,5 +46,6 @@ export {
|
|||||||
hasBrowserEnv,
|
hasBrowserEnv,
|
||||||
hasStandardBrowserWebWorkerEnv,
|
hasStandardBrowserWebWorkerEnv,
|
||||||
hasStandardBrowserEnv,
|
hasStandardBrowserEnv,
|
||||||
|
_navigator as navigator,
|
||||||
origin
|
origin
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user