Skip to content

Commit 597f663

Browse files
authored
fix: Disable non-browser enviornments session tracking in @sentry/browser (#3194)
1 parent 8267e30 commit 597f663

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/browser/src/sdk.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { getCurrentHub, initAndBind, Integrations as CoreIntegrations, SDK_VERSION } from '@sentry/core';
2-
import { addInstrumentationHandler, getGlobalObject, SyncPromise } from '@sentry/utils';
2+
import { addInstrumentationHandler, getGlobalObject, logger, SyncPromise } from '@sentry/utils';
33

44
import { BrowserOptions } from './backend';
55
import { BrowserClient } from './client';
@@ -192,6 +192,13 @@ export function wrap(fn: (...args: any) => any): any {
192192
*/
193193
function startSessionTracking(): void {
194194
const window = getGlobalObject<Window>();
195+
const document = window.document;
196+
197+
if (typeof document === 'undefined') {
198+
logger.warn('Session tracking in non-browser environment with @sentry/browser is not supported.')
199+
return;
200+
}
201+
195202
const hub = getCurrentHub();
196203

197204
/**

0 commit comments

Comments
 (0)