-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Instrumenting EventTarget.prototype.addEventListener leads to problems in Chrome #2074
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
Comments
I'm stumbling across this error as well. This occurs sometimes when calling the global function addEventListener("someevent", callback) Calling it with a "this parameter" resolves the issue: window.addEventListener("someevent", callback) Sadly, I don't reproduce it consistently. The only thing I can think of is that in the first case, I am using EDIT: joining a screenshot of the detailed list of impacted browsers |
This is only happening for us when we're using OpenLayers to create a new map. As a result, I've decided to ditch OL for Leaflet (probably a good move in general), and I'm just hoping this solves my issue. |
I managed to write a minimal program to reproduce this consistently. Just run it in your console devtools: const original = EventTarget.prototype.addEventListener
EventTarget.prototype.addEventListener = function (eventName, fn, options) {
"use strict"
original.call(this, eventName, fn, options)
}
for (var i = 0; i < 100000; i += 1) {
if (i % 100 === 0) console.log(i)
addEventListener("mouseup", () => {})
} In my case, it throws after the 4600th iteration. |
On a semi-related note, when I remove Sentry, LogRocket trips up in a very similar way. |
@BenoitZugmeyer @ffxsam thanks for the repro case. After further investigation, I can tell that it's not our SDK issue, it's just Chrome's limit for event listeners per object. When you call the repro above on any page (be it http://example.com) it will break as well. No SDK required. |
Yes, this is a Chrome issue. But incuding your SDK triggers that issue, breaking our code. Lucky for me this is easily fixable in my codebase, but I would be a bit annoyed if it occured in a dependency like @ffxsam |
@BenoitZugmeyer how so? We don't add our own listeners. We only intercept user's calls to |
Basically, in your SDK, you are doing this to intercept const original = EventTarget.prototype.addEventListener
EventTarget.prototype.addEventListener = function (eventName, fn, options) {
"use strict"
original.call(this, eventName, fn, options)
} Removing those lines from the snippet I gave you (meaning: removing your SDK in my code) fixes the issue: we can add as many event listeners as needed. So of course you don't add listeners on you own, but the Chrome bug is triggered by the way you are intercepting |
@BenoitZugmeyer you are right here, my bad. It's because of mentioned strict mode. The only thing we can do here is disable, and then it all works just fine 🤷♂ const original = EventTarget.prototype.addEventListener
EventTarget.prototype.addEventListener = function (eventName, fn, options) {
original.call(this, eventName, fn, options)
}
for (var i = 0; i < 100000; i += 1) {
if (i % 100 === 0) console.log(i)
addEventListener("mouseup", () => {})
} |
I guess you could also do something like |
/*! @sentry/browser 5.2.1 (a5b87c1e) | https://github.com/getsentry/sentry-javascript */
var Sentry = (function (exports) {
'use strict'; Although |
I reported the issue here: https://bugs.chromium.org/p/chromium/issues/detail?id=964249 I think it wouldn't alter the code behavior because calling the original |
Awesome, thanks! And in the meantime #2078 |
EDIT: found a cleaner workaround: Sentry.init({
...
// XXX: Workaround for https://github.com/getsentry/sentry-javascript/issues/2074
defaultIntegrations: Sentry.defaultIntegrations.filter(({ name }) => name !== 'TryCatch'),
}); old stuff
I'm opting for this workaround for now. EventTarget.prototype.addEventListener = EventTarget.prototype.addEventListener.__sentry_original__;
EventTarget.prototype.removeEventListener = EventTarget.prototype.removeEventListener.__sentry_original__; |
@javan fixed pending PR tests, we will release patch this week. |
I'm still seeing this on Running this snippet in the console still throws when sentry is enabled. for (var i = 0; i < 100000; i += 1) {
if (i % 100 === 0) console.log(i)
addEventListener("mouseup", () => {})
} |
Same. Issue is still present in v5.3.0. Example: https://sentry-browser-chrome-bug.glitch.me |
It appears that using For example, this snippet tickles the Chrome bug: const original = EventTarget.prototype.addEventListener
EventTarget.prototype.addEventListener = function(eventName, fn, options) {
"use strict"
original.call(this, eventName, fn, options)
}
let count = 0
while (count++ < 10000) addEventListener("click", console.log) This one does not: const original = EventTarget.prototype.addEventListener
EventTarget.prototype.addEventListener = function() {
"use strict"
original.apply(this, arguments)
}
let count = 0
while (count++ < 10000) addEventListener("click", console.log) |
Also, @kamilogorek, I think this issue should be reopened. |
Done. Although I'll need some time to take a look at it, as I'm busy with other work. Any help appreciated :) |
May 23, 2019 March 13, 2020 |
I haven't found any relevant uses of |
We still see many errors coming from Chrome 74 Mobile. Interestingly, there's no issue with I guess babel transpile somehow eliminate the usage of buggy function call in Chrome 74 somehow Our hole website only targets es6 (es2015) so we hope to use es6 build |
@Fonger can you provide a link to the affected event ever here or directly to [email protected]? Thanks |
@kamilogorek sure. just emailed We had rollbacked to use |
Hey! Sorry to do a plus one on this but seems we are also encountering this at codesandbox and its been also in the bunches: Interesting thing is that it seems to only happen on chrome on a mac You can see the user created crash report here: codesandbox/codesandbox-client#5326 Let me know if you need anything else or any help in this |
Cross-posting for the reference: codesandbox/codesandbox-client#5406 (comment) |
…on (#4695) Users have reported running into a bug in Chrome wherein calling `addEventListener` or `requestAnimationFrame` too many times on `window` eventually throws an error when our `try-catch` integration is running, specifically because of how we wrap those functions. In the discussion of that bug, [one user](#2074 (comment)) reported that replacing our `call` call with an `apply` call in our wrapping functions solved the problem for him. This makes that change, in the hopes it will fix the problem for everyone. Fixes #3388 Fixes #2074
Package + Version
@sentry/browser
5.2.0Description
We're getting this error:
Cannot convert undefined or null to object
It seems to be happening here, according to Chrome:
https://github.com/getsentry/sentry-javascript/blob/master/packages/browser/src/integrations/trycatch.ts#L88
Here's the stack trace:
Here's a snapshot of the error in Chrome DevTools:
Seems like OpenLayers is throwing an error, but Sentry is not handling it properly and throwing an error itself.
The text was updated successfully, but these errors were encountered: