Detecting and handling blocked scripts
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>
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
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?
Yes, you're coding it correctly. Do you know of any JS libraries that can detect script blocking by Ghostery/Adblock in all browsers?
Hmm, to be honest, I've actually never looked. ¯_(ツ)_/¯
Ok, I'll look for a library that can detect script blocking by Ghostery/Adblock. Let me know if you find something sooner.