Skip to content

Commit e44368c

Browse files
f1234kteemaxx
andauthored
fix: unambiguously detect web workers (#1728)
Co-authored-by: Thomas Minitsios <[email protected]>
1 parent f6123f2 commit e44368c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/lib/is-browser.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
const isBrowser =
22
(typeof window !== 'undefined' && typeof window.document !== 'undefined') ||
33
// eslint-disable-next-line no-restricted-globals
4-
(typeof self !== 'undefined' && typeof self.postMessage === 'function') || // is web worker
4+
(typeof self === 'object' &&
5+
// eslint-disable-next-line no-restricted-globals
6+
self.constructor &&
7+
// eslint-disable-next-line no-restricted-globals
8+
self.constructor.name === 'DedicatedWorkerGlobalScope') || // is web worker
59
(typeof navigator !== 'undefined' && navigator.product === 'ReactNative') // while navigator.product is deprecated
10+
611
export default isBrowser

0 commit comments

Comments
 (0)