Skip to content

Instantly share code, notes, and snippets.

@elbywan
Created June 7, 2018 08:40
Show Gist options
  • Save elbywan/2967eb39e10ad219e95b166bb77fa2df to your computer and use it in GitHub Desktop.
Save elbywan/2967eb39e10ad219e95b166bb77fa2df to your computer and use it in GitHub Desktop.
const observer = new MutationObserver(mutations => {
mutations.forEach(({ addedNodes }) => {
addedNodes.forEach(node => {
// For each added script tag
if(node.nodeType === 1 && node.tagName === 'SCRIPT') {
const src = node.src || ''
const type = node.type
// If the src is inside your blacklist
if(needsToBeBlacklisted(src, type)) {
// Do some stuff that will prevent the script tag loading ;)
// (See below…)
}
}
})
})
})
// Starts the monitoring
observer.observe(document.documentElement, {
childList: true,
subtree: true
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment