loadjs icon indicating copy to clipboard operation
loadjs copied to clipboard

Detecting and handling blocked scripts

Open michaelroper opened this issue 8 years ago • 5 comments

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>

michaelroper avatar Jun 06 '17 07:06 michaelroper

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

amorey avatar Jun 06 '17 12:06 amorey

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?

michaelroper avatar Jun 06 '17 14:06 michaelroper

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

amorey avatar Jun 06 '17 14:06 amorey

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

michaelroper avatar Jun 06 '17 15:06 michaelroper

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

amorey avatar Jun 06 '17 15:06 amorey