Skip to content

Commit 159977a

Browse files
authored
fix(replay): Allow Replay to be used in Electron renderers with nodeIntegration enabled (#6644)
1 parent 4b97518 commit 159977a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

packages/replay/src/integration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ Sentry.init({ replaysOnErrorSampleRate: ${errorSampleRate} })`,
127127
: `${this.recordingOptions.blockSelector},${MEDIA_SELECTORS}`;
128128
}
129129

130-
if (isBrowser() && this._isInitialized) {
130+
if (this._isInitialized && isBrowser()) {
131131
throw new Error('Multiple Sentry Session Replay instances are not supported');
132132
}
133133

packages/replay/src/util/isBrowser.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,12 @@ import { isNodeEnv } from '@sentry/utils';
22

33
export function isBrowser(): boolean {
44
// eslint-disable-next-line no-restricted-globals
5-
return typeof window !== 'undefined' && !isNodeEnv();
5+
return typeof window !== 'undefined' && (!isNodeEnv() || isElectronNodeRenderer());
6+
}
7+
8+
type ElectronProcess = { type?: string };
9+
10+
// Electron renderers with nodeIntegration enabled are detected as Node.js so we specifically test for them
11+
function isElectronNodeRenderer(): boolean {
12+
return typeof process !== 'undefined' && (process as ElectronProcess).type === 'renderer';
613
}

0 commit comments

Comments
 (0)