UNPKG

@sentry/browser

Version:
40 lines (37 loc) 1.47 kB
import { defineIntegration, debug, startSession, captureSession, getIsolationScope } from '@sentry/core/browser'; import { addHistoryInstrumentationHandler } from '@sentry-internal/browser-utils'; import { DEBUG_BUILD } from '../debug-build.js'; import { WINDOW } from '../helpers.js'; const browserSessionIntegration = defineIntegration((options = {}) => { const lifecycle = options.lifecycle ?? "route"; return { name: "BrowserSession", setupOnce() { if (typeof WINDOW.document === "undefined") { DEBUG_BUILD && debug.warn("Using the `browserSessionIntegration` in non-browser environments is not supported."); return; } startSession({ ignoreDuration: true }); captureSession(); const isolationScope = getIsolationScope(); let previousUser = isolationScope.getUser(); isolationScope.addScopeListener((scope) => { const maybeNewUser = scope.getUser(); if (previousUser?.id !== maybeNewUser?.id || previousUser?.ip_address !== maybeNewUser?.ip_address) { captureSession(); previousUser = maybeNewUser; } }); if (lifecycle === "route") { addHistoryInstrumentationHandler(({ from, to }) => { if (from !== to) { startSession({ ignoreDuration: true }); captureSession(); } }); } } }; }); export { browserSessionIntegration }; //# sourceMappingURL=browsersession.js.map