-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: improve environment detection in is-browser utility (#1744)
- Loading branch information
1 parent
4e77c77
commit b094142
Showing
1 changed file
with
15 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,18 @@ | ||
const isBrowser = | ||
(typeof window !== 'undefined' && typeof window.document !== 'undefined') || | ||
// eslint-disable-next-line no-restricted-globals | ||
(typeof self === 'object' && | ||
// eslint-disable-next-line no-restricted-globals | ||
self.constructor && | ||
const isStandardBrowserEnv = () => | ||
typeof window !== 'undefined' && typeof window.document !== 'undefined' | ||
|
||
const isWebWorkerEnv = () => | ||
Boolean( | ||
// eslint-disable-next-line no-restricted-globals | ||
self.constructor.name === 'DedicatedWorkerGlobalScope') || // is web worker | ||
(typeof navigator !== 'undefined' && navigator.product === 'ReactNative') // while navigator.product is deprecated | ||
typeof self === 'object' && | ||
// eslint-disable-next-line no-restricted-globals | ||
self?.constructor?.name?.includes('WorkerGlobalScope'), | ||
) | ||
|
||
const isReactNativeEnv = () => | ||
typeof navigator !== 'undefined' && navigator.product === 'ReactNative' | ||
|
||
const isBrowser = | ||
isStandardBrowserEnv() || isWebWorkerEnv() || isReactNativeEnv() | ||
|
||
export default isBrowser |