Skip to content

Instantly share code, notes, and snippets.

@elbywan
Created June 7, 2018 08:40
Show Gist options
  • Save elbywan/5138c9f3bbafa3f5826186e022beadae to your computer and use it in GitHub Desktop.
Save elbywan/5138c9f3bbafa3f5826186e022beadae to your computer and use it in GitHub Desktop.
// Assume that this code is executed inside the mutation observer callback:
addedNodes.forEach(node => {
// See above for script tag checks…
node.type = 'javascript/blocked'
// Firefox has this additional event which prevents scripts from beeing executed
const beforeScriptExecuteListener = function (event) {
// Prevent only marked scripts from executing
if(node.getAttribute('type') === 'javascript/blocked')
event.preventDefault()
node.removeEventListener('beforescriptexecute', beforeScriptExecuteListener)
}
node.addEventListener('beforescriptexecute', beforeScriptExecuteListener)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment