Detect/prevent the creation of already existing iframe tags

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/786

A case of web page embedding multiple times the
`adsbygoogle.js` script was causing the neutered,
replacement script to create a huge amount of iframes
in the DOM.

The scriptlet has been modified to check if an iframe
tag already exist and skip the creation if so.
This commit is contained in:
Raymond Hill 2019-11-19 08:49:38 -05:00
parent 18b6a6ba18
commit bdd4a5bf5a
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 4 additions and 2 deletions

View File

@ -37,10 +37,12 @@
const css = 'height:1px!important;max-height:1px!important;max-width:1px!important;width:1px!important;';
for ( let i = 0; i < phs.length; i++ ) {
const fr = document.createElement('iframe');
fr.id = 'aswift_' + (i+1);
const id = `aswift_${(i+1)}`;
if ( document.querySelector(`iframe#${id}`) !== null ) { continue; }
fr.id = id;
fr.style = css;
const cfr = document.createElement('iframe');
cfr.id = 'google_ads_frame' + i;
cfr.id = `google_ads_frame${i}`;
fr.appendChild(cfr);
document.body.appendChild(fr);
}