fix(web): fail operations on a hung page at their timeout, not the test timeout
Merged
OK
2mo ago+662+662+012345678901234567890123456789-96-96-01234567890123456789
A web test on a page whose script never yields (a button that starts while (true) {}) waited for the whole test timeout instead of failing at actionTimeout.
- Root cause:
guardandAttemptSession.runonly raced the attempt signal, so the operation'stimeoutMswas enforced by Playwright alone. On a renderer stuck in a script, Playwright never answers an evaluate (locateruns one, with no timeout) or a mouse or keyboard call, and while a trace records (the local default) evenclick({ timeout })andgoto({ timeout })stay pending past their timeout. - Fix: every guarded operation now runs under its budget's deadline (
withOperationDeadline,packages/web/src/operation-budget.ts) and fails asOPERATION_TIMEOUT(ACTION_FAILEDin the report). Playwright gets a timeout 250 ms shorter, so when it can answer, its classified error (NOT_ACTIONABLE ... intercepts pointer events,ACTION_MAY_HAVE_COMMITTED) still arrives first. - A tap, point action, or keystroke the deadline cut off is
ACTION_MAY_HAVE_COMMITTED, not a plain timeout: the input may have landed, so replay hands off asaction-uncertaininstead of repeating it. waitForDownloadruns the test's trigger, so the deadline does not cut it: the waiter keeps its full timeout and theno download started within <n>msmessage names it.e2e: with locate bounded, a read that starts with under 100 ms of a wait left can time out because the wait did. Such a cut-off read, after one that completed, now ends the wait on its last sample (cutOffAtDeadline,packages/e2e/src/internal/time.ts): a missing locator staysLOCATOR_NOT_FOUND, a missing frame keeps its reason, an assertion keepsASSERTION_FAILED, each with the timeout ascause. A read that started with more budget and still timed out hung, and staysACTION_FAILED; a negation never passes on it.docs/reference/engine.mdxsays so.expect(browser)matchers (toHaveURL,toHaveTitle,toHaveClass) read within the assertion's remaining budget instead of the action timeout, and report their last sample, so on a frozen page they end at their own timeout.hung-page.test.tscovers it.app.open()to a server that never answers was already bounded by Playwright'sgototimeout. Its documented budget isconfig.timeout(docs/reference/app.mdx), which by default equals the test timeout, so it still ends at the test timeout by design. It now reports the navigation'sACTION_FAILEDrather thanTEST_TIMEOUT, and 5 s sooner.
Tests: packages/web/tests/integration/hung-page.test.ts (locate, point tap, traced tap, traced navigation on a frozen page fail on main with "still pending"; each call must also take its whole budget; a covered button keeps NOT_ACTIONABLE, which fails if the 250 ms lead is removed), time.test.ts and locator-engine.test.ts cases for the cut-off rule (a hung read stays a failure and a negation does not pass on it; mutation-checked), and a failure-evidence.test.ts case.
Verified
Ran it locally: yes
- testbed, built CLI, a scratch test (not committed) that serves a never-answering URL and a page whose button runs
while (true) {}, each test{ timeout: 60_000 }:
test('opens a server that never answers', { timeout: 60_000 }, async ({ app }) => {
await app.open(`${origin}/never`);
});
test('taps a button that freezes the page', { timeout: 60_000 }, async ({ app, screen }) => {
await app.open(`${origin}/`);
await screen.getByRole('button', { name: 'Freeze' }).tap();
});
| config | test | main | this branch |
|---|---|---|---|
testbed default (actionTimeout 30 s, timeout 120 s) | tap on frozen page | 70.0 s, TEST_TIMEOUT | 35.1 s, ACTION_FAILED (tap step 30.0 s) |
| testbed default | open never-answering server | 70.1 s, TEST_TIMEOUT | 64.9 s, ACTION_FAILED (open step 59.8 s) |
actionTimeout: 5_000, timeout: 10_000 | tap on frozen page | 70.0 s, TEST_TIMEOUT | 10.1 s, ACTION_FAILED (tap step 5.0 s) |
actionTimeout: 5_000, timeout: 10_000 | open never-answering server | 20.1 s, ACTION_FAILED (open step 10.1 s) | 14.9 s, ACTION_FAILED (open step 9.8 s) |
actionTimeout: 5_000, timeout: 10_000 | not.toBeVisible({ timeout: 3_000 }) after freezing | not run on main | 9.2 s, ACTION_FAILED (assertion step 3.0 s) |
The rest of each attempt after the failing step is the 5 s failure-evidence look.
main:
× opens a server that never answers (timed-out) 70.13s
→ test timed out after 60000 ms in phase body
× taps a button that freezes the page (timed-out) 70.02s
→ test timed out after 60000 ms in phase body
this branch:
× opens a server that never answers 64.88s
→ operation timed out
× taps a button that freezes the page 35.07s
→ tap timed out before the page answered; its input may have been dispatch…