TypeError when calling Array.prototype.find on HTMLAllCollection
Closed this issue ยท 9 comments
The shimmed version of Array.prototype.find
raises a TypeError
when called on an HTMLAllCollection
.
This is happening in v54.0.2840.71
of Chrome.
Here is a codepen that reproduces this bug in Chrome: http://codepen.io/pifantastic/pen/vyLxGq
Array.prototype.find.call(document.all, (item, idx) => console.log)
// Uncaught TypeError: Cannot call method on [object HTMLAllCollection](โฆ)
document.all
is HIGHLY deprecated, and should never be used - try document.querySelectorAll('*')
instead, if you really want that.
document.all
is a special case as the only falsy object in all of JS and browsers, and there's not a reliable way for me to detect it - but it's been a bad practice for over a decade to use it.
@ljharb Yep. We don't actually use it. Apparently a lot of browser extensions do though :(
We reported this due to a big spike in errors in our error reporting service. I understand if you're not interested in fixing it at the es6-shim level. We can find a workaround on our side.
@aaron-stripe i'd love to fix it if there's a proper way to do it, but document.all
is a pretty horrifically bad thing to have explicit support for :-/
The codepen is helpful - can you point me to some libraries that are trying to pass document.all
into Array.prototype.find
? The latter is new enough that these libs should be PR-able to do the right thing instead.
@ljharb unfortunately I don't know what library is responsible. From our end we can't see much, and our best guess is that it's a browser extension that is doing something on each page load. I can tell you that we first saw it happening ~ Nov 9, 2016 6:37:08 PM UTC
. I will definitely post more details if I can figure out how to get them.
If someone interested, VueJS Devtools extension for Chrome causes this error too. But I don't think that a lot of @aaron-stripe users have devtools installed.
@tzurbaev amazing! The timing on this lines up pretty well, it's possible that VueJS Devtools is causing the issue I'm seeing. I just opened a PR with a fix.
@aaron-stripe since that PR is merged, let's give it a few days to land. If the errors don't subside, I'll write an awful hack to make this work here.
I ended up writing the awful hack. The next release will include this fix.
@ljharb thanks :)