Skip to content

Instantly share code, notes, and snippets.

@zachvictor
Last active August 17, 2020 04:59
Show Gist options
  • Save zachvictor/b1946555ca3dadfcda7d1d7ec01d9ba0 to your computer and use it in GitHub Desktop.
Save zachvictor/b1946555ca3dadfcda7d1d7ec01d9ba0 to your computer and use it in GitHub Desktop.
JavaScript for browser console kills on page iframes + uses MutationObserver to kill new iframes
(function () {
function __kill_added_iframe_mutob_callback(mList, ob){
const addedNodesToRemove = []
mList.forEach(mRec => {
mRec.addedNodes.forEach(addedNode => {
if (addedNode.tagName.match(/^iframe$/i)) {
addedNodesToRemove.push(addedNode)
}
})
})
addedNodesToRemove.forEach(nodeToRemove => {
console.log('removing 1 ' + nodeToRemove.tagName)
nodeToRemove.remove()
})
}
const __kill_added_iframe_mutob = new MutationObserver(__kill_added_iframe_mutob_callback)
__kill_added_iframe_mutob.observe(document.body, {
attributes: false,
childList: true,
subtree: false
})
window.__kill_added_iframe_mutob = __kill_added_iframe_mutob
// init
document.querySelectorAll('iframe').forEach(iframe => iframe.remove())
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment