fix(web): continue skips earlier routes, decisions take or reject Playwright options

Merged
OK
2mo ago
+731-98

Four web routing bugs, all in packages/web/src/browser.ts.

  • continue() answered from an earlier route. It called Playwright's route.fallback(), so a broad fulfill registered earlier answered instead of the network. It now calls route.continue(), which skips every other route. The site-header route (web({ headers }), protected-app.ts) was reached only through that chain, so continue now 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 }), and abort('failed') all acted as if no argument was passed. New route-options.ts checks every key before the decision is taken:
    • continue now takes url, method, headers, and postData. url goes through context.app.resolveUrl (relative URLs resolve, file: is POLICY_DENIED) and must keep the request's scheme.
    • fulfill now takes path (relative to the project root, checked before deciding) and contentType. A content-type header wins over the type json or path would set.
    • Unknown keys go through rejectUnknownOptions from e2e/engine (#579), so the message matches the other browser options.
    • Any other key, two body sources, abort(code), or fallback(overrides) is INVALID_ARGUMENT. The request is aborted and the next step fails.
    • Header overrides follow the web({ headers }) grammar (shared headerProblem): an invalid name or a control character is INVALID_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.
  • waitForResponse counted the body read against the match timeout. Headers at 0ms with the body at 1200ms and { timeout: 500 } gave ACTION_FAILED. The timeout now bounds only the match, as in Playwright. The body read still starts at once, and text()/json() wait for it on their own action budget, so an endless body fails as ACTION_FAILED instead of a test timeout.
  • setCookies([{ url: '/' }]) threw ENGINE_FAILURE. It discarded resolveUrl's result and passed / to addCookies. It now sets the resolved URL, and still refuses an about:blank target (#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/proj with web({ headers: { 'x-gate': ... } }), against a local server that counts hits per path and echoes requests. The same suite ran against main's @e2e-dev/web dist and this branch's.
casemainthis branch
B53 earlier fulfill, later continue()fail: "earlier-mock"pass: network-x
continue() keeps the site gate headerpasspass
continue({ headers })fail: header missingpass, gate header still added
continue({ url: '/echo', method, postData })fail: original endpoint answeredpass, 0 hits on original
continue({ url }) to another sitefail: original endpoint answeredpass, no gate header off-site
continue({ url: 'file:///etc/hosts' })silently continued to the originalPOLICY_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 bodyINVALID_ARGUMENT: route.fulfill options has no key "bodyy"; ...
fallback() to the earlier routefail: Failed to fetch (no such method)pass: earlier-mock
B9 waitForResponse 500ms, body at 1200msACTION_FAILED: exceeded its timeout of 500mspass, text() is slow-body
N53 setCookies([{ url: '/' }])ENGINE_FAILURE: addCookies: Invalid URLpass, cookie on 127.0.0.1
  • New packages/web/tests/integration/routes.test.ts (27 cases) and 2 new cases in wait-for-response.test.ts. With main's browser.ts, surface.ts, and protected-app.ts swapped in, 25 of the 32 cases in the two files fail. On main, the non-JSON json case hangs until the 30s test timeout.
  • Rebased on main after #722 (http(s) and about:blank navigation allowlist). On the rebased build, continue({ url }) with view-source: or data: is POLICY_DENIED, and about:blank is INVALID_ARGUMENT (must keep the request's http: scheme). The repro suite gave the same results as the table. The routes.test.ts resolver 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/e2e web-platform and web-url-patterns passed (29). Did not run the web benchmark locally; CI runs it.

Left open

  • The configured headers reach an off-site redirect target. This also happens on main with no test route, because the site-header route's fallback({ headers }) carries them onto redirects. It needs an owner decision on the invariant. See the escalated Devin and cubic threads.