Last active
August 17, 2020 04:59
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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