Skip to content

Commit

Permalink
fix(tracing): Add check for document.scripts in metrics
Browse files Browse the repository at this point in the history
Fixes #3705

Supersedes #3707

We should check if document.scripts exists as it does not exist in some
browser environments. This patch also refectors the document logic
to rely on `global.document` instead of `document`.
  • Loading branch information
AbhiPrasad committed Jun 29, 2021
1 parent 3f53fef commit 65a1490
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions packages/tracing/src/browser/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ export class MetricsInstrumentation {
const timeOrigin = msToSec(browserPerformanceTimeOrigin);
let entryScriptSrc: string | undefined;

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

0 comments on commit 65a1490

Please sign in to comment.