Skip to content

Commit

Permalink
fix: unambiguously detect web workers (#1728)
Browse files Browse the repository at this point in the history
Co-authored-by: Thomas Minitsios <[email protected]>
  • Loading branch information
f1234k and teemaxx authored Oct 30, 2023
1 parent f6123f2 commit e44368c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/lib/is-browser.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const isBrowser =
(typeof window !== 'undefined' && typeof window.document !== 'undefined') ||
// eslint-disable-next-line no-restricted-globals
(typeof self !== 'undefined' && typeof self.postMessage === 'function') || // is web worker
(typeof self === 'object' &&
// eslint-disable-next-line no-restricted-globals
self.constructor &&
// 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

export default isBrowser

0 comments on commit e44368c

Please sign in to comment.