Repository navigation
Arm request interception when a test page is made - #231
Merged
Merged
Conversation
A route registered on an already-loaded Chromium page can miss the very request it was installed to hold: Playwright acknowledges page.route before the browser has armed interception, so a POST issued milliseconds later reaches the server with neither a route callback nor a request event. The nightly failure in #226 is that escape — the page posted the comment, the server appended it, and the answer settled the draft, while the test's counters read nothing and its wait ran out. open_page now arms each page it makes on a pattern nothing ever asks for, beside the Traffic watcher and before the first navigation. Nothing is intercepted by it and no request's behavior changes; a route registered later only adds a pattern to a list the browser is already consulting. Refs #226
max-sixty
added a commit
that referenced
this pull request
Oct 25, 2026
Every page the suite made armed request interception before it navigated (`arm_interception` in `readable`), so that a route a test adds later catches the next request (#231). While a page has any route, Playwright enables `Fetch` on `*` and turns Chromium's HTTP cache off (`_updateProtocolRequestInterceptionForSession` in the driver), so every request the page makes waits for a round trip through the driver. Most pages are never routed. A page the suite makes now arms itself when something first routes it or its context, ahead of that route: - Before navigation, nothing is in flight, so the arm is registered as before. `held_events` and `primed` keep holding the first navigation's requests. - After navigation, the arm proves interception is on before the test's route is added. The page fetches `/favicon.ico?lf-interception-armed=N`, which the arm answers with 204, and the page fetches again until one is caught. A probe that escapes reaches the page server's quiet `favicon.ico`, so it leaves nothing in the console. - A page made in a context that has a route arms as it is made. `unroute_all` takes the arm with it, so the next route arms again. The arm stays for the page's life, as before, so the route list never empties under requests in flight. Unrouted pages now run with Chromium's HTTP cache on, as a user's browser does. The page server marks revision resources `immutable` and everything else `no-cache`, so a reload revalidates against the server rather than reusing stale state. ## Where an opening's time goes Measured on one plain test page (`SETTLED_PAGE`) on an M-series Mac, `-n0`, median of 9 openings at load averages 7–9 (October 25 2026): | Phase | Wall | | --- | --: | | `serve`: page loan from the pool, `page stamp` | ~55 ms (Python) | | New context and page, `readable`'s init scripts | ~40 ms | | `goto` to `load` (document 9 ms, `DOMContentLoaded` 98 ms, 48 requests, 2.9 MB) | ~95 ms | | `load` to `wait_until_ready` returning (`upgraded` at 170 ms, `presented` at 178 ms) | ~110 ms | | `one_frame` after readiness | ~18 ms | The renderer's main thread was busy 117 ms of that (script 31 ms, style 21 ms, layout 5 ms) with no shift watch installed, and 137 ms with it. CPU per opening across every process, 20 openings per round, five interleaved rounds, load averages 11–14, median: | Process | Base | This change | | --- | --: | --: | | Chrome renderer | 250 ms | 250 ms | | Chrome browser process | 72 ms | 53 ms | | Chrome network and GPU processes | 43 ms | 35 ms | | Playwright driver | 40 ms | 36 ms | | Test process (page server threads and Playwright client) | 169 ms | 171 ms | | **Total** | **573 ms** | **546 ms** | Every round was lower with this change (base 544–599 ms, this change 518–592 ms). ## Whole files `tests/browser/test_render_options.py`, `test_render_reactions.py`, `widgets/test_tabs.py`, `navigation/test_panes.py` and `test_render_floating_panel.py` (300 tests, `-n 3`), three interleaved rounds, CPU from `/usr/bin/time` over the whole process tree: | | CPU | Wall | | --- | --: | --: | | Base | 366.4, 366.6, 375.9 s | 106.2, 105.6, 108.0 s | | This change | 357.7, 350.9, 356.9 s | 104.9, 102.7, 104.4 s | That is 2.6% less CPU and 1.7% less wall time (load averages 11–20). CI's runner is CPU-bound with three workers on four cores, so the saving there should track the CPU column; main's next push run will show it. ## Coverage - The route-heavy files pass on this change: `test_render_outbox.py`, `drafts/test_sending.py`, `drafts/test_shared_drafts.py`, `startup/test_freshness.py`, `startup/test_readiness.py`, `startup/test_hosting.py`, `startup/test_modules.py`, `widgets/test_tabs.py`, `projection/test_thread_replies.py`, `test_render_application_boundary.py` (234 tests), and `test_render_gate.py`, `startup/test_versions.py`, `projection/test_live_versions.py`, `drafts/test_revisions.py`, `widgets/test_playgrounds.py`, `test_render_commands.py`, `test_render_pages.py`, `smoke/test_smoke.py`, `test_widget_quality.py` (279 tests and 31 subtests). - A route that misses its request fails its test, since every held route is followed by a wait for the held request (`holding`) that times out. The race #231 found therefore couldn't pass a test vacuously; it made it flaky. - I couldn't reproduce that race with Playwright 1.63. A route registered after navigation, followed at once by a fetch, caught it in 80 of 80 runs with no arm at all, including 60 under `--cpu-throttle 8` at `-n 3`. The probe keeps the guarantee either way, and costs about 5 ms on a page that routes. - Bug-back for the probe: with `ARM_PROBE` changed to a pattern the probe never matches, a late `page.route` raises `request interception never caught a probe` at the deadline, and the escaped probes leave the browser fixture clean. - `test_another_key_or_a_scroll_away_puts_the_shown_gesture_back_to_showing` (`test_render_outbox.py`) times out intermittently at `-n 3` on main too (two failures in four runs of the file on the merge base), so a failure there is inherited. > _This was written by Claude Code on behalf of max-sixty_
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.
Problem
The nightly
cifailures in #226 are the suite losing a send, not the page swallowing a press. Ontest_a_comment_hidden_by_narrowing_is_revealed_in_the_open_panelthe page does everything right: theEnterposts the comment, the server appends it, the answer settles the draft and the composer closes. What never happens is Playwright seeing that POST — neither the route the test installed a keystroke earlier norpage.on("request")reports it — soTraffic.sendsstays at nought and the wait times out on counters that were never going to move.Chromium arms request interception the first time a page is routed at all, and Playwright's acknowledgement of
page.routeoutruns that arming. A request issued in the milliseconds after the call goes straight to the server. It is the escapeheld_eventswas already written around, andtests/CLAUDE.mdalready names it — the guidance was to route from navigation onward, which twenty-nine livepage.route("**/api/event", …)sites do not.Solution
open_pagearms each page it makes on a pattern nothing ever asks for, beside theTrafficwatcher and before the first navigation. Nothing is intercepted by it and no request's behavior changes; a route a test registers later only adds a pattern to a list the browser is already consulting.tests/CLAUDE.mdstates the invariant beside the rule it completes.Testing
Reproduced first, at ~1 run in 12, by running the named case under eight CPU burners on this four-core runner. Instrumenting
placeFab,showFab,settleAcceptedDraftsandpostEventin a failing run gave the mechanism above; the issue's own diagnosis (the placement gate withdrawing the bar) is ruled out —placeFabnever returned false, and the bar was still being placed while the withdrawal came fromsettleAcceptedDraftsclosing a composer whose draft the server had genuinely accepted.test_a_comment_hidden_by_narrowing_is_revealed_in_the_open_panelthen ran 40 more times under the same load with no failure.tests/test_render_drafts.pyis 61 passed; the everyday suite is 807 passed, 6 skipped. The change costs nothing measurable — that file runs 43.8s without it and 44.7s with it.The other failure in #226 is a different defect, fixed in #227
test_render_reactions.py::test_spilled_reactions_keep_their_target_and_yield_to_the_map[click-390]failed with the same counters on the next nightly run, but it installs no route at all, so interception cannot be its cause. #227 traces that one to a<dialog>closelanding after its own reopen and clearing the new opening's target. The two failures share a shape and nothing else.Fixes the drafts half of #226; #227 has the reactions half.