fix(browser): pause intercepted subresources instead of blocking them - #644
Open
marcoripa96 wants to merge 1 commit into
Open
fix(browser): pause intercepted subresources instead of blocking them#644marcoripa96 wants to merge 1 commit into
marcoripa96 wants to merge 1 commit into
Conversation
should_block_url treated Fetch interception patterns as a block list, so any script or stylesheet matching them was dropped before fetch and the client never asked. Puppeteer's setRequestInterception enables Fetch with pattern *, which made every subresource of every page silently vanish the moment interception was on: a client aborting only *.css* lost all scripts too, and WordPress pages died on "wp is not defined" with their JS-rendered content missing. Route matched static subresources (scripts, stylesheets, stylesheet imports) through the existing InterceptedRequest channel and obey the client's verdict: Continue (with URL override), Fail (skip), Fulfill (use the provided response). Empty pattern list means intercept everything, matching Fetch.enable's default and the library's enable_interception(). Fail-open on a closed channel or a client that does not answer within 5s so a crashed client cannot stall rendering. should_block_url now consults only Network.setBlockedURLs patterns. Fixes h4ckf0r0day#643
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #643.
should_block_urltreated Fetch interception patterns as a block list, so any<script src>or<link rel="stylesheet">matching them was dropped before fetch and the client never asked. Puppeteer'ssetRequestInterception(true)enables Fetch with pattern*, so in practice every subresource of every page silently vanished the moment a puppeteer client turned interception on, whatever its request handler intended — a handler aborting only*.css*lost all scripts too, and pages whose inline scripts depend on external ones died on ReferenceErrors with their JS-rendered content missing.Changes:
should_block_urlconsults onlyNetwork.setBlockedURLspatterns.@imports) matching active interception patterns are paused on the existingInterceptedRequestchannel (the oneop_fetch_urlalready uses forfetch()/XHR) and the client's verdict is obeyed: Continue (with URL override), Fail (skip the resource), Fulfill (use the provided response).Fetch.enable's default and the library'senable_interception().linked_stylesheet_graph_fetches_once_and_preserves_order_and_basesencoded the old semantics (pattern match with no client attached = silent drop); it now attaches an interception client that refuses the matched stylesheet, which is the contract CDP specifies.Test plan:
crates/obscura/tests/subresource_interception.rs: a page with one stylesheet, one external script, and an inline script depending on it; the interception client aborts.cssand continues the rest. On main the script never runs and neither request reaches the client; with the fix the script executes, the stylesheet is skipped, and both requests reach the client.cargo nextest run -p obscura -p obscura-cdp -p obscura-cli -p obscura-mcp -p obscura-browser: 244 passed, 3 skipped.observer-intersectionfailure, see fix(js): bind computed style methods passed through to the declaration #636's test plan).