diff --git a/packages/replay/src/integration.ts b/packages/replay/src/integration.ts index b68ddd7f11fa..449c19ec9f00 100644 --- a/packages/replay/src/integration.ts +++ b/packages/replay/src/integration.ts @@ -120,7 +120,7 @@ Sentry.init({ replaysOnErrorSampleRate: ${errorSampleRate} })`, : `${this.recordingOptions.blockSelector},${MEDIA_SELECTORS}`; } - if (isBrowser() && this._isInitialized) { + if (this._isInitialized && isBrowser()) { throw new Error('Multiple Sentry Session Replay instances are not supported'); } diff --git a/packages/replay/src/util/isBrowser.ts b/packages/replay/src/util/isBrowser.ts index fb87bc3c7e55..3ad78dce93a5 100644 --- a/packages/replay/src/util/isBrowser.ts +++ b/packages/replay/src/util/isBrowser.ts @@ -2,5 +2,12 @@ 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() || isElectronNodeRenderer()); +} + +type ElectronProcess = { type?: string }; + +// Electron renderers with nodeIntegration enabled are detected as Node.js so we specifically test for them +function isElectronNodeRenderer(): boolean { + return typeof process !== 'undefined' && (process as ElectronProcess).type === 'renderer'; }