From bdd4a5bf5adb737483c19a5fc19f5a34b7866801 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 19 Nov 2019 08:49:38 -0500 Subject: [PATCH] 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. --- .../googlesyndication_adsbygoogle.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/web_accessible_resources/googlesyndication_adsbygoogle.js b/src/web_accessible_resources/googlesyndication_adsbygoogle.js index 4a2da9676..5a6fc82bc 100644 --- a/src/web_accessible_resources/googlesyndication_adsbygoogle.js +++ b/src/web_accessible_resources/googlesyndication_adsbygoogle.js @@ -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); }