Skip to content

There are not 'document.scripts' in mini-program environment #3705

Closed
@janpoem

Description

@janpoem

Package + Version

  • @sentry/browser
  • @sentry/node
  • raven-js
  • raven-node (raven for node)
  • @sentry/tracing

Version:

6.4.1

Description

Use '@sentry/tracing' in mini-program environment, when call Sentry.startTransaction on a page launch at the first time, whould catch the error as below:

TypeError: Cannot read property 'length' of undefined
    at MetricsInstrumentation.define.push../node_modules/@sentry/tracing/esm/browser/metrics.js.MetricsInstrumentation.addPerformanceEntries (common.js?t=wechat&s=1623694839553&v=ba7f9072bea7d2c8b9666326b3c638e8:6416)
    at common.js?t=wechat&s=1623694839553&v=ba7f9072bea7d2c8b9666326b3c638e8:6315
    at IdleTransaction.define.push../node_modules/@sentry/tracing/esm/idletransaction.js.IdleTransaction.finish (common.js?t=wechat&s=1623694839553&v=ba7f9072bea7d2c8b9666326b3c638e8:7949)
    at Function.<anonymous> (common.js?t=wechat&s=1623694839553&v=ba7f9072bea7d2c8b9666326b3c638e8:7932)
    at :12319/appservice/<setTimeout callback function>
    at VM214 WAService.js:2
    at VM214 WAService.js:2(env: macOS,mp,1.05.2105170; lib: 2.17.0)

Check this error in file /node_modules/@sentry/tracing/esm/browser/metrics.js:

        // line 34
        if (global.document) {
            // eslint-disable-next-line @typescript-eslint/prefer-for-of
            for (var i = 0; i < document.scripts.length; i++) { // => There are not document.scripts in mini-program
                // 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;
                    break;
                }
            }
        }

I think should change if (global.document) to if (global.document && document.scripts != null) will fix this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions