Skip to content

Commit 5289d40

Browse files
authored
fix(tracing): Add check for document.scripts in metrics (#3766)
Fixes #3705 Supersedes #3707 We should check if document.scripts exists as it does not exist in some browser environments. This patch also refactors the document logic to rely on `global.document` instead of `document`.
1 parent a732ae8 commit 5289d40

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/tracing/src/browser/metrics.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ export class MetricsInstrumentation {
4646
const timeOrigin = msToSec(browserPerformanceTimeOrigin);
4747
let entryScriptSrc: string | undefined;
4848

49-
if (global.document) {
49+
if (global.document && global.document.scripts) {
5050
// eslint-disable-next-line @typescript-eslint/prefer-for-of
51-
for (let i = 0; i < document.scripts.length; i++) {
51+
for (let i = 0; i < global.document.scripts.length; i++) {
5252
// We go through all scripts on the page and look for 'data-entry'
5353
// We remember the name and measure the time between this script finished loading and
5454
// our mark 'sentry-tracing-init'
55-
if (document.scripts[i].dataset.entry === 'true') {
56-
entryScriptSrc = document.scripts[i].src;
55+
if (global.document.scripts[i].dataset.entry === 'true') {
56+
entryScriptSrc = global.document.scripts[i].src;
5757
break;
5858
}
5959
}

0 commit comments

Comments
 (0)