File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { SampleContext, TransactionContext } from '@sentry/types';
33import {
44 dynamicRequire ,
55 extractNodeRequestData ,
6+ getGlobalObject ,
67 hasTracingEnabled ,
78 isInstanceOf ,
89 isNodeEnv ,
@@ -123,9 +124,14 @@ function getDefaultSampleContext(): SampleContext {
123124
124125 // we must be in browser-js (or some derivative thereof)
125126 else {
126- // we take a copy of the location object rather than just a reference to it in case there's a navigation in the
127- // instant between when the transaction starts and when the sampler is called
128- defaultSampleContext . location = { ...window . location } ;
127+ // we use `getGlobalObject()` rather than `window` since service workers also have a `location` property on `self`
128+ const globalObject = getGlobalObject ( ) ;
129+
130+ if ( 'location' in globalObject ) {
131+ // we take a copy of the location object rather than just a reference to it in case there's a navigation or
132+ // redirect in the instant between when the transaction starts and when the sampler is called
133+ defaultSampleContext . location = { ...globalObject . location } ;
134+ }
129135 }
130136
131137 return defaultSampleContext ;
You can’t perform that action at this time.
0 commit comments