codekingpro/portable-devtools
114k
1const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';2 3/**4 * Determine if we're running in a standard browser environment5 *6 * This allows axios to run in a web worker, and react-native.7 * Both environments support XMLHttpRequest, but not fully standard globals.8 *9 * web workers:10 * typeof window -> undefined11 * typeof document -> undefined12 *13 * react-native:14 * navigator.product -> 'ReactNative'15 * nativescript16 * navigator.product -> 'NativeScript' or 'NS'17 *18 * @returns {boolean}19 */20const hasStandardBrowserEnv = (21 (product) => {22 return hasBrowserEnv && ['ReactNative', 'NativeScript', 'NS'].indexOf(product) < 023 })(typeof navigator !== 'undefined' && navigator.product);24 25/**26 * Determine if we're running in a standard browser webWorker environment27 *28 * Although the `isStandardBrowserEnv` method indicates that29 * `allows axios to run in a web worker`, the WebWorker will still be30 * filtered out due to its judgment standard31 * `typeof window !== 'undefined' && typeof document !== 'undefined'`.32 * This leads to a problem when axios post `FormData` in webWorker33 */34const hasStandardBrowserWebWorkerEnv = (() => {35 return (36 typeof WorkerGlobalScope !== 'undefined' &&37 // eslint-disable-next-line no-undef38 self instanceof WorkerGlobalScope &&39 typeof self.importScripts === 'function'40 );41})();42 43export {44 hasBrowserEnv,45 hasStandardBrowserWebWorkerEnv,46 hasStandardBrowserEnv47}48 