Skip to content

Commit f40cba0

Browse files
committed
fix(tracing): Guard against missing window.location (#10659)
We should also backport this to v7, probably. Closes #10578
1 parent 01f6386 commit f40cba0

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/tracing-internal/src/browser/browserTracingIntegration.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
257257
isPageloadTransaction, // should wait for finish signal if it's a pageload transaction
258258
);
259259

260-
if (isPageloadTransaction) {
260+
if (isPageloadTransaction && WINDOW.document) {
261261
WINDOW.document.addEventListener('readystatechange', () => {
262262
if (['interactive', 'complete'].includes(WINDOW.document.readyState)) {
263263
idleTransaction.sendAutoFinishSignal();
@@ -307,7 +307,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
307307
}
308308

309309
let activeSpan: Span | undefined;
310-
let startingUrl: string | undefined = WINDOW.location.href;
310+
let startingUrl: string | undefined = WINDOW.location && WINDOW.location.href;
311311

312312
if (client.on) {
313313
client.on('startNavigationSpan', (context: StartSpanOptions) => {
@@ -335,7 +335,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
335335
});
336336
}
337337

338-
if (options.instrumentPageLoad && client.emit) {
338+
if (options.instrumentPageLoad && client.emit && WINDOW.location) {
339339
const context: StartSpanOptions = {
340340
name: WINDOW.location.pathname,
341341
// pageload should always start at timeOrigin (and needs to be in s, not ms)
@@ -348,7 +348,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
348348
startBrowserTracingPageLoadSpan(client, context);
349349
}
350350

351-
if (options.instrumentNavigation && client.emit) {
351+
if (options.instrumentNavigation && client.emit && WINDOW.location) {
352352
addHistoryInstrumentationHandler(({ to, from }) => {
353353
/**
354354
* This early return is there to account for some cases where a navigation transaction starts right after

0 commit comments

Comments
 (0)