From 7e5d14dfdb2caa60e40c844384afe9cc84347eab Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Wed, 4 Jan 2023 11:54:21 +0100 Subject: [PATCH] feat(replay): Allow to capture replays for electron --- packages/replay/src/util/isBrowser.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/replay/src/util/isBrowser.ts b/packages/replay/src/util/isBrowser.ts index fb87bc3c7e55..5a84ecb6263e 100644 --- a/packages/replay/src/util/isBrowser.ts +++ b/packages/replay/src/util/isBrowser.ts @@ -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); }