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';
3
3
import {
4
4
dynamicRequire ,
5
5
extractNodeRequestData ,
6
+ getGlobalObject ,
6
7
hasTracingEnabled ,
7
8
isInstanceOf ,
8
9
isNodeEnv ,
@@ -123,9 +124,14 @@ function getDefaultSampleContext(): SampleContext {
123
124
124
125
// we must be in browser-js (or some derivative thereof)
125
126
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
+ }
129
135
}
130
136
131
137
return defaultSampleContext ;
You can’t perform that action at this time.
0 commit comments