Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion packages/replay/src/util/isBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,15 @@ import { isNodeEnv } from '@sentry/utils';

export function isBrowser(): boolean {
// eslint-disable-next-line no-restricted-globals
return typeof window !== 'undefined' && !isNodeEnv();
return typeof window !== 'undefined' && (!isNodeEnv() || isElectron(window));
}

/*
Electron renderers with nodeIntegration enabled have process defined, which means they will trigger `isNodeEnv() === false`.
This has not been the default config for a couple of years and it's not recommended but it's still used a lot in real world applications.
So in order to ensure we can still capture for Electron apps, we need to check for the userAgent string.
*/
function isElectron(window: Window): boolean {
// See: https://github.com/electron/electron/issues/2288
return /electron/i.test(window.navigator.userAgent);
}