From a6ca24b846796fd5997c7270385db1f9d3ecec46 Mon Sep 17 00:00:00 2001 From: TheGeneralist <180094941+thegeneralist01@users.noreply.github.com> Date: Wed, 8 Jul 2026 10:59:21 +0200 Subject: [PATCH] fix: dispatch single-file-user-script-init so request hook fires single-file's initUserScriptHandler (in single-file-bootstrap.js) listens for 'single-file-user-script-init' and only then installs _singleFile_waitForUserScript. Without that dispatch our scripts' 'single-file-on-before-capture-request' listeners were never reached, so neither strip-scripts nor reader-mode Readability applied. Dispatch the init event at the top of strip-scripts (always present) and redundantly in READER_MODE_SCRIPT. Verified end-to-end: artifact for run_b3181d6d276e4e56a1a6c356ef9bbe8f has meta content="applied", max-width:680px CSS, 0 script tags. --- crates/archivr-core/src/downloader/singlefile.rs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/crates/archivr-core/src/downloader/singlefile.rs b/crates/archivr-core/src/downloader/singlefile.rs index 6654cff..52525b9 100644 --- a/crates/archivr-core/src/downloader/singlefile.rs +++ b/crates/archivr-core/src/downloader/singlefile.rs @@ -85,6 +85,9 @@ const READER_MODE_SCRIPT: &str = concat!( _archivrReaderMark('failed:exception:' + (e && e.message ? e.message : String(e))); } } + // Ensure _singleFile_waitForUserScript is installed (strip-scripts also does + // this, but be explicit here in case reader-mode ever runs without it). + dispatchEvent(new CustomEvent('single-file-user-script-init')); // Synchronous work — no preventDefault()/response dispatch needed. addEventListener('single-file-on-before-capture-request', _archivrApplyReader); })(); @@ -217,10 +220,13 @@ fn save_with( let strip_scripts_path = temp_dir.join("sf-strip-scripts.js"); std::fs::write( &strip_scripts_path, - "addEventListener('single-file-on-before-capture-request',()=>{\ - document.querySelectorAll('script:not([type=\"application/ld+json\"])')\ - .forEach(el=>el.remove());\ - });", + // Dispatch single-file-user-script-init so single-file installs + // _singleFile_waitForUserScript, which gates the -request hooks. + "dispatchEvent(new CustomEvent('single-file-user-script-init'));\ + addEventListener('single-file-on-before-capture-request',()=>{\ + document.querySelectorAll('script:not([type=\"application/ld+json\"])')\ + .forEach(el=>el.remove());\ + });", ) .context("failed to write single-file user script")?;