Skip to content

Commit

Permalink
fix(tracing): Guard against missing window.location (#10659)
Browse files Browse the repository at this point in the history
We should also backport this to v7, probably.

Closes #10578
  • Loading branch information
mydea committed Feb 15, 2024
1 parent 575e5c8 commit 4917612
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
isPageloadTransaction, // should wait for finish signal if it's a pageload transaction
);

if (isPageloadTransaction) {
if (isPageloadTransaction && WINDOW.document) {
WINDOW.document.addEventListener('readystatechange', () => {
if (['interactive', 'complete'].includes(WINDOW.document.readyState)) {
idleTransaction.sendAutoFinishSignal();
Expand Down Expand Up @@ -295,7 +295,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
options;

let activeSpan: Span | undefined;
let startingUrl: string | undefined = WINDOW.location.href;
let startingUrl: string | undefined = WINDOW.location && WINDOW.location.href;

client.on('startNavigationSpan', (context: StartSpanOptions) => {
if (activeSpan) {
Expand All @@ -321,7 +321,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
});
});

if (options.instrumentPageLoad) {
if (options.instrumentPageLoad && WINDOW.location) {
const context: StartSpanOptions = {
name: WINDOW.location.pathname,
// pageload should always start at timeOrigin (and needs to be in s, not ms)
Expand All @@ -334,7 +334,7 @@ export const browserTracingIntegration = ((_options: Partial<BrowserTracingOptio
startBrowserTracingPageLoadSpan(client, context);
}

if (options.instrumentNavigation) {
if (options.instrumentNavigation && WINDOW.location) {
addHistoryInstrumentationHandler(({ to, from }) => {
/**
* This early return is there to account for some cases where a navigation transaction starts right after
Expand Down

0 comments on commit 4917612

Please sign in to comment.