From 5a9c65551a02bdaf2b2027012c846be238d2eb9e Mon Sep 17 00:00:00 2001 From: TheGeneralist <180094941+thegeneralist01@users.noreply.github.com> Date: Wed, 8 Jul 2026 22:38:02 +0200 Subject: [PATCH] fix: remove ad placeholders when uBlock active; kept height causes blank gap uBlock Origin Lite blocks ad network requests but first-party placeholder elements (ins.adsbygoogle, #aswift_* iframe hosts) retain their computed height (e.g. 280px for a top banner), leaving a large blank space at the top of captured pages. Gate cleanup on ublock_ext.is_some(): remove ins.adsbygoogle, aswift_* iframes, and google_ads_* iframes before SingleFile serialises. Also collapse the parent container if it becomes empty after removal. --- .../archivr-core/src/downloader/singlefile.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crates/archivr-core/src/downloader/singlefile.rs b/crates/archivr-core/src/downloader/singlefile.rs index 4d225aa..98f8422 100644 --- a/crates/archivr-core/src/downloader/singlefile.rs +++ b/crates/archivr-core/src/downloader/singlefile.rs @@ -292,6 +292,27 @@ fn save_with( ).forEach(function(el){el.remove();});", ); } + if ublock_ext.is_some() { + // uBlock blocks ad network requests but first-party ad placeholder + // elements (ins.adsbygoogle, iframe hosts) retain their computed + // height, leaving blank space. Remove them pre-capture. + strip_scripts.push_str( + "document.querySelectorAll(\ + 'ins.adsbygoogle,\ + [id^=\"aswift_\"],\ + iframe[id^=\"google_ads_\"],\ + iframe[name^=\"google_ads_frame\"],\ + iframe[src*=\"googlesyndication\"],\ + iframe[src*=\"doubleclick\"]'\ + ).forEach(function(el){\ + var p=el.parentElement;\ + el.remove();\ + /* collapse parent if it's now empty and was ad-only */\ + if(p&&!p.textContent.trim()&&p.children.length===0)\ + p.style.display='none';\ + });", + ); + } strip_scripts.push_str("});"); std::fs::write(&strip_scripts_path, &strip_scripts) .context("failed to write single-file user script")?;