kubetail-org / loadjs

A tiny async loader / dependency manager for modern browsers (899 bytes)
MIT License
2.57k stars 149 forks source link

Detecting and handling blocked scripts #47

Open michaelroper opened 7 years ago

michaelroper commented 7 years ago

Hey! I'm trying to figure out how to detect and handle if an external tracker script has been blocked by Ghostery/AdBlock - but my test code below only ever seems to trigger success, even if I'm using Ghostery to explicitly block the Marketo script (and I don't see that script load in DevTools either). Am I doing it wrong?


loadjs(['https://munchkin.marketo.net/munchkin-beta.js'], 'marketo');
loadjs.ready('marketo', {
    success: function() {
        console.log('pass!');
    },
    error: function(depsNotFound) {
        console.log('fail!');
    }
});
</script>
amorey commented 7 years ago

Do you know the mechanism that the blocker is using to block the script? Currently, LoadJS is configured to detect script blocking via the defaultPrevented mechanism: https://github.com/muicss/loadjs/blob/master/src/loadjs.js#L164-L169

michaelroper commented 7 years ago

Hey Andres - not sure what the mechanism is, this was testing with Ghostery on Chrome/Mac. Interestingly, I just installed Ghostery on Safari/Mac, blocked Marketo, and it DID throw the error... so I'm not sure what the difference is. Have I coded that correctly for this situation?

amorey commented 7 years ago

Yes, you're coding it correctly. Do you know of any JS libraries that can detect script blocking by Ghostery/Adblock in all browsers?

michaelroper commented 7 years ago

Hmm, to be honest, I've actually never looked. ¯_(ツ)_/¯

amorey commented 7 years ago

Ok, I'll look for a library that can detect script blocking by Ghostery/Adblock. Let me know if you find something sooner.