fix(web): continue skips earlier routes, decisions take or reject Playwright options
Merged
OK
2mo ago+731+731+012345678901234567890123456789-98-98-01234567890123456789
Four web routing bugs, all in packages/web/src/browser.ts.
continue()answered from an earlier route. It called Playwright'sroute.fallback(), so a broadfulfillregistered earlier answered instead of the network. It now callsroute.continue(), which skips every other route. The site-header route (web({ headers }),protected-app.ts) was reached only through that chain, socontinuenow merges those headers itself, for the final URL's site only (surface.siteHeaders).- New
route.fallback()keeps the old chaining under Playwright's name. It takes no overrides: an overridden URL could take the gate header off-site. - Unsupported options were silently ignored.
continue({ headers | url }),fulfill({ path | contentType }), andabort('failed')all acted as if no argument was passed. Newroute-options.tschecks every key before the decision is taken:continuenow takesurl,method,headers, andpostData.urlgoes throughcontext.app.resolveUrl(relative URLs resolve,file:isPOLICY_DENIED) and must keep the request's scheme.fulfillnow takespath(relative to the project root, checked before deciding) andcontentType. Acontent-typeheader wins over the typejsonorpathwould set.- Unknown keys go through
rejectUnknownOptionsfrome2e/engine(#579), so the message matches the other browser options. - Any other key, two body sources,
abort(code), orfallback(overrides)isINVALID_ARGUMENT. The request is aborted and the next step fails. - Header overrides follow the
web({ headers })grammar (sharedheaderProblem): an invalid name or a control character isINVALID_ARGUMENT. - A Playwright decision call that throws after deciding now aborts the request instead of leaving it pending. Before,
fulfill({ json: 1n })hung the page's fetch.
waitForResponsecounted the body read against the match timeout. Headers at 0ms with the body at 1200ms and{ timeout: 500 }gaveACTION_FAILED. The timeout now bounds only the match, as in Playwright. The body read still starts at once, andtext()/json()wait for it on their own action budget, so an endless body fails asACTION_FAILEDinstead of a test timeout.setCookies([{ url: '/' }])threwENGINE_FAILURE. It discardedresolveUrl's result and passed/toaddCookies. It now sets the resolved URL, and still refuses anabout:blanktarget (#722).
Routes still run newest first:
await browser.route('**/api/**', (route) => route.fulfill({ body: 'mock' }));
await browser.route('**/api/live', (route) => route.continue()); // network, mock skipped
await browser.route('**/api/chain', (route) => route.fallback()); // 'mock'
await browser.route('**/api/file', (route) => route.fulfill({ path: 'fixtures/quote.json' }));
Docs: docs/reference/web.mdx (routing, types, cookies), docs/browser.mdx, docs/migrate/playwright.mdx (rows moved from missing to web only), skills/e2e/references/writing-tests.md. Compile-time assertions are in packages/web/tests/types/routes.ts.
Verified
Ran it locally: yes
- Ran the built CLI (
node packages/e2e/dist/cli/bin.js run) on a scratch project at/tmp/oskar-fix-web-routing/projwithweb({ headers: { 'x-gate': ... } }), against a local server that counts hits per path and echoes requests. The same suite ran against main's@e2e-dev/webdist and this branch's.
| case | main | this branch |
|---|---|---|
B53 earlier fulfill, later continue() | fail: "earlier-mock" | pass: network-x |
continue() keeps the site gate header | pass | pass |
continue({ headers }) | fail: header missing | pass, gate header still added |
continue({ url: '/echo', method, postData }) | fail: original endpoint answered | pass, 0 hits on original |
continue({ url }) to another site | fail: original endpoint answered | pass, no gate header off-site |
continue({ url: 'file:///etc/hosts' }) | silently continued to the original | POLICY_DENIED: forbidden URL scheme: file: |
fulfill({ path }) / fulfill({ contentType }) | fail: ["",null,null] | pass: bytes, application/json, given type |
fulfill({ bodyy }) (typo) | passed silently with an empty body | INVALID_ARGUMENT: route.fulfill options has no key "bodyy"; ... |
fallback() to the earlier route | fail: Failed to fetch (no such method) | pass: earlier-mock |
B9 waitForResponse 500ms, body at 1200ms | ACTION_FAILED: exceeded its timeout of 500ms | pass, text() is slow-body |
N53 setCookies([{ url: '/' }]) | ENGINE_FAILURE: addCookies: Invalid URL | pass, cookie on 127.0.0.1 |
- New
packages/web/tests/integration/routes.test.ts(27 cases) and 2 new cases inwait-for-response.test.ts. With main'sbrowser.ts,surface.ts, andprotected-app.tsswapped in, 25 of the 32 cases in the two files fail. On main, the non-JSONjsoncase hangs until the 30s test timeout. - Rebased on main after #722 (http(s) and
about:blanknavigation allowlist). On the rebased build,continue({ url })withview-source:ordata:isPOLICY_DENIED, andabout:blankisINVALID_ARGUMENT(must keep the request'shttp:scheme). The repro suite gave the same results as the table. Theroutes.test.tsresolver fake now follows the allowlist, with cases for both. - The testbed suite passed (70 passed, 1 skipped), run on a different port to avoid other local runs. The routing cases in
packages/e2eweb-platformandweb-url-patternspassed (29). Did not run the web benchmark locally; CI runs it.
Left open
- The configured
headersreach an off-site redirect target. This also happens on main with no test route, because the site-header route'sfallback({ headers })carries them onto redirects. It needs an owner decision on the invariant. See the escalated Devin and cubic threads.