walmartlabs / little-loader

A lightweight, IE8+ JavaScript loader
MIT License
370 stars 28 forks source link

Ad blockers causing exception to be thrown #51

Open jknight12882 opened 7 years ago

jknight12882 commented 7 years ago

... in the _addScript function, namely when the <script /> node is inserted into the DOM. These should be caught and returned in the callback

ryan-roemer commented 7 years ago

@jknight12882 -- Can you give us a little more information and (if possible) a failing unit test case example?

Do you mean that something like:

try {
  _addScript(script);
} catch (err) {
  // We now have an `err` from the actual `_addScript()` call (?)
}
jknight12882 commented 7 years ago

The use case occurs when we try to load Omniture analytics tracking. The error is:

screen shot 2016-12-05 at 3 09 21 pm

Which refers to the (Uglified) _addScript function

screen shot 2016-12-05 at 3 09 35 pm
ryan-roemer commented 7 years ago

Can you paste the stack trace / error message? I'm curious as to why it looks like t.parentNode doesn't have an insertBefore(n, t) or why that failed...

And reading what you've pasted, it looks like the GET fails for /vendor/s_code.min.js which theoretically should be handled by the error handlers by little-loader (assuming you're using the err object in the callback).

ryan-roemer commented 7 years ago

Alternately, if the omniture stuff isn't closed source, you could maybe create a jsbin or something repro-ing your issue so we can dive in with more info?

jknight12882 commented 7 years ago

It's only handled if asynchronous. This is a synchronous error being thrown when trying to insert the dom. I'm using ublock which is looking at the name of the js being inserted and comparing it against a blacklist of known names, and then rejecting.

ryan-roemer commented 7 years ago

Gotcha. Can you give me a full stack trace so I can see where I should be try/catch-ing? It looks around the insertBefore call?

jknight12882 commented 7 years ago

Best I can do at this exact moment as we're inlining and wrapping the library to allow for parallel loading of multiple scripts

screen shot 2016-12-05 at 3 24 33 pm
jknight12882 commented 7 years ago
screen shot 2016-12-05 at 3 27 00 pm
ryan-roemer commented 7 years ago

Thanks for the info.