Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unhandledRejection: TypeError: globalScope.addEventListener is not a function #942

Open
zherr opened this issue Jan 8, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@zherr
Copy link

zherr commented Jan 8, 2025

Expected Behavior

This exception should not be raised when autocapture options are enabled (seen with pageViews, formInteractions, and fileDownloads, but shouldn't happen with any configuration), or when offline mode is enabled (which is the default).

Current Behavior

One of four different exceptions are raised:

TypeError: _a.addEventListener is not a function
    at eval (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/lib/esm/plugins/file-download-tracking.js:39:145)
    at step (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:183:21)
    at Object.eval [as next] (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:164:51)
    at eval (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:157:69)
    at new Promise (<anonymous>)
    at __awaiter (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:153:10)
    at Object.setup (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/lib/esm/plugins/file-download-tracking.js:32:103)
    at Timeline.eval (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/node_modules/@amplitude/analytics-core/lib/esm/timeline.js:37:107)
    at step (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:183:21)
    at Object.eval [as next] (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:164:51)
    at eval (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:157:69)
    at new Promise (<anonymous>)
    at __awaiter (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:153:10)
    at Timeline.register (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/node_modules/@amplitude/analytics-core/lib/esm/timeline.js:23:64)
    at AmplitudeCore._addPlugin (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/node_modules/@amplitude/analytics-core/lib/esm/core-client.js:124:99)
    at AmplitudeCore.add (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/node_modules/@amplitude/analytics-core/lib/esm/core-client.js:121:21)
    at AmplitudeBrowser.eval (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/lib/esm/browser-client.js:136:51)
    at step (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:183:21)
    at Object.eval [as next] (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:164:51)
    at fulfilled (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:154:56)
⨯ unhandledRejection: TypeError: _a.addEventListener is not a function
   at eval (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/lib/esm/plugins/file-download-tracking.js:39:145)
   at step (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:183:21)
   at Object.eval [as next] (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:164:51)
   at eval (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:157:69)
   at new Promise (<anonymous>)
   at __awaiter (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:153:10)
   at Object.setup (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/lib/esm/plugins/file-download-tracking.js:32:103)
   at Timeline.eval (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/node_modules/@amplitude/analytics-core/lib/esm/timeline.js:37:107)
   at step (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:183:21)
   at Object.eval [as next] (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:164:51)
   at eval (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:157:69)
   at new Promise (<anonymous>)
   at __awaiter (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:153:10)
   at Timeline.register (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/node_modules/@amplitude/analytics-core/lib/esm/timeline.js:23:64)
   at AmplitudeCore._addPlugin (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/node_modules/@amplitude/analytics-core/lib/esm/core-client.js:124:99)
   at AmplitudeCore.add (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/node_modules/@amplitude/analytics-core/lib/esm/core-client.js:121:21)
   at AmplitudeBrowser.eval (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/lib/esm/browser-client.js:136:51)
   at step (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:183:21)
   at Object.eval [as next] (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:164:51)
   at fulfilled (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:154:56)
unhandledRejection: TypeError: _a.addEventListener is not a function
 at eval (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/lib/esm/plugins/file-download-tracking.js:39:145)
 at step (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:183:21)
 at Object.eval [as next] (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:164:51)
 at eval (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:157:69)
 at new Promise (<anonymous>)
 at __awaiter (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:153:10)
 at Object.setup (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/lib/esm/plugins/file-download-tracking.js:32:103)
 at Timeline.eval (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/node_modules/@amplitude/analytics-core/lib/esm/timeline.js:37:107)
 at step (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:183:21)
 at Object.eval [as next] (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:164:51)
 at eval (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:157:69)
 at new Promise (<anonymous>)
 at __awaiter (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:153:10)
 at Timeline.register (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/node_modules/@amplitude/analytics-core/lib/esm/timeline.js:23:64)
 at AmplitudeCore._addPlugin (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/node_modules/@amplitude/analytics-core/lib/esm/core-client.js:124:99)
 at AmplitudeCore.add (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/node_modules/@amplitude/analytics-core/lib/esm/core-client.js:121:21)
 at AmplitudeBrowser.eval (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/lib/esm/browser-client.js:136:51)
 at step (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:183:21)
 at Object.eval [as next] (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:164:51)
 at fulfilled (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:154:56)
TypeError: globalScope.addEventListener is not a function
    at addNetworkListener (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/lib/esm/plugins/network-connectivity-checker.js:16:25)
    at eval (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/lib/esm/plugins/network-connectivity-checker.js:40:13)
    at step (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:183:21)
    at Object.eval [as next] (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:164:51)
    at eval (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:157:69)
    at new Promise (<anonymous>)
    at __awaiter (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:153:10)
    at Object.setup (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/lib/esm/plugins/network-connectivity-checker.js:32:103)
    at Timeline.eval (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/node_modules/@amplitude/analytics-core/lib/esm/timeline.js:37:107)
    at step (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:183:21)
    at Object.eval [as next] (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:164:51)
    at eval (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:157:69)
    at new Promise (<anonymous>)
    at __awaiter (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:153:10)
    at Timeline.register (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/node_modules/@amplitude/analytics-core/lib/esm/timeline.js:23:64)
    at AmplitudeCore._addPlugin (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/node_modules/@amplitude/analytics-core/lib/esm/core-client.js:124:99)
    at AmplitudeCore.add (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/node_modules/@amplitude/analytics-core/lib/esm/core-client.js:121:21)
    at AmplitudeBrowser.eval (webpack-internal:///(rsc)/./node_modules/@amplitude/analytics-browser/lib/esm/browser-client.js:119:51)
    at step (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:183:21)
    at Object.eval [as next] (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:164:51)
    at fulfilled (webpack-internal:///(rsc)/./node_modules/tslib/tslib.es6.mjs:154:56)

Possible Solution

Disabling these autocapture features circumvents these errors, but is not ideal:

autocapture: {
  pageViews: false,
  formInteractions: false,
  fileDownloads: false,
},
offline: amplitude.Types.OfflineDisabled,

Steps to Reproduce

  1. Call amplitude.init( with autocapture enabled on a standard NextJS page.tsx
  2. Observe exceptions

Environment

  • JS SDK Version: "@amplitude/analytics-browser": "^2.11.10",
  • Installation Method: npm
  • Browser and Version: Firefox, latest
@zherr zherr added the bug Something isn't working label Jan 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant