paulmillr / es6-shim

ECMAScript 6 compatibility shims for legacy JS engines
http://paulmillr.com
MIT License
3.11k stars 387 forks source link

TypeError when calling Array.prototype.find on HTMLAllCollection #428

Closed aaron-stripe closed 7 years ago

aaron-stripe commented 7 years ago

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](…)

screenshot 2016-11-10 13 46 49

ljharb commented 7 years ago

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.

aaron-stripe commented 7 years ago

@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.

ljharb commented 7 years ago

@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.

aaron-stripe commented 7 years ago

@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.

tzurbaev commented 7 years ago

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.

aaron-stripe commented 7 years ago

@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.

ljharb commented 7 years ago

@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.

ljharb commented 7 years ago

I ended up writing the awful hack. The next release will include this fix.

aaron-stripe commented 7 years ago

@ljharb thanks :)