Saturday 15 September 2012

javascript - How to stop a new node being added to DOM using chrome/firefox extension? -



javascript - How to stop a new node being added to DOM using chrome/firefox extension? -

i writing extension observe malicious behavior of scripts. these scripts add together nodes dom after page gets loaded. able these nodes using

document.addeventlistener("domnodeinserted", checkcontents, false);

but how can stop them beingness loaded? can done in chrome or firefox?

use mutationobserver childlist , subtree.

var grid = iframe.contentdocument.getelementbyid('newtab-grid'); var mobs = new iframe.contentwindow.mutationobserver(function(mutations) { mutations.foreach(function(mutation) { console.log(mutation.type, mutation); if (mutation.addednodes && mutation.addednodes.length > 0) { var link = mutation.target.queryselector('.newtab-link'); if (link) { link.setattribute('target', '_parent'); console.log('set target on el') } else { console.log('this ell has no link added el') } } }); }); mobs.observe(grid, { childlist: !0, subtree: !0 });

now tell when addingnodes , gives added in mutation.addednodes. can iterate throuh , remove added. i'm not sure if can prevent adding, can remove after added.

https://developer.mozilla.org/en-us/docs/web/api/mutationobserver?redirectlocale=en-us&redirectslug=dom%2fmutationobserver#mutationobserverinit

javascript javascript-events google-chrome-extension firefox-addon mutation-observers

No comments:

Post a Comment