feat(web): answer unhandled native dialogs with web({ dialogs }) (ENG-963)
What
web({ dialogs: 'accept' | 'dismiss' }) answers every native dialog (alert, confirm, prompt, beforeunload) that no browser.onDialog handler takes, in every test of the target:
targets: [{ name: 'web', engine: web({ dialogs: 'accept' }), app: { url: 'http://localhost:3000' } }],
An accepted prompt returns its default text, as clicking OK does. Each dialog the option answers is a line in the attempt's app log, so a message the app shows only in an alert stays in the report and trace.md. The agent action that opened the dialog shows the model the same line in its result, so an explorer still reads an app's error alert:
Tapped #n6.
Screen unchanged since revision b4 (re-observed as revision b30, path /); the ids you have stay valid.
System log (not on the screen):
- alert dialog "Could not save: server error 500" opened; accepting it per web({ dialogs: 'accept' })
A handler a test registers still answers first. With the option unset, nothing changes except the error, which now names both fixes:
APP_NOT_OPEN: unhandled confirm dialog: Delete Invoice 42?; register a handler with browser.onDialog, or answer every dialog with web({ dialogs: 'accept' }) or web({ dialogs: 'dismiss' })
Why
e2e explore and agent.act steps can't register browser.onDialog. A confirm() behind a Delete button was dismissed, and the tap came back to the explorer as Action failed: unhandled confirm dialog: ..., which no tool can answer. Deletion charters in a bug bash never got past it. The option gives a config a way to answer those dialogs.
How it works
DialogRoutertakes the policy and the attempt's app log beside its latch (packages/web/src/dialogs.ts:45).routetries the newest registered handler first. With none and a policy set,answerwrites onesystemline to the app log, such asalert dialog "Could not save" opened; accepting it per web({ dialogs: 'accept' }), then accepts withdialog.defaultValue()or dismisses (packages/web/src/dialogs.ts:83,:99). The line is written before the answer, while the step that opened the dialog is still running, so it says the answer is under way. Playwright's bareaccept()would answer a prompt with an empty string. Without the line, an app's erroralertwould close with no trace, where without the option it failed the step with its message. A failure to answer is latched asENGINE_FAILUREand the dialog is dismissed, as a failing handler's is. A handler's answer is the test's own and is not logged.- With no handler and no policy, the dialog is dismissed and
INVALID_STATEis latched as before. The message now namesbrowser.onDialogandweb({ dialogs })(packages/web/src/dialogs.ts:111). A function handler that answers neither way still fails, policy or not: the handler took the dialog. PlaywrightSurfacereadsoptions.dialogsand passes it to the router it creates at construction and at eachstartAttempt, which also getscontext.appLog(packages/web/src/surface.ts:423,:613). Only the attempt's router receives dialogs.web()validates the option at config load (packages/web/src/engine.ts:110). Any other value isINVALID_CONFIGnaming only the value's kind, never the value: a config can pass any string there, andweb()throws before the runner knows the config's secrets.DialogPolicyis exported besideDialogHandler.- The agent shows the model those lines. The session's app log route keeps the newest five
systemlines apart from its quota and sink, behind a cursor (systemLines,packages/core/src/engine/session.ts:114,surface.ts:171). Each agent step's observation feed takes the cursor when the step starts and reads the lines logged since its previous look on every executorobserve, whitespace collapsed, redacted, and cut at 300 characters (packages/core/src/agent/observation-feed.ts:121,:245). They reach the executor asExecutorObservation.systemLog(packages/core/src/agent/executor.ts:181), so a custom executor gets them too. The built-in agent ande2e mcplist them under the screen in every rendering of a look: an action's result, the opening screen, MCP'sobserve, andrun_code(packages/core/src/agent/screen-update.ts:223,:302,:345). The note comes after the lead and the screen's headline, which the loop guards read. Each line is shown once, with the first look after it. An action whose look carries a line is never reported as having no visible effect, since analertchanges nothing listed (:360). Lines read by looks an action takes on its way are carried into its result: the scroll repeats (primitives.ts) and the agent's second opening look for pixels (default-agent.ts). Transcript compaction keeps the note when it elides an old screen (transcript-compaction.ts:164). The engine contract and the wire do not change:AppLogEntry's doc now says asystemline also reaches the model. The model-input list inAGENTS.mdanddocs/reference/security.mdxnames it. - Docs:
reference/web.mdx: adialogsentry (options table, entry with what each answer returns, itsENGINE_FAILURE, the app log's limits, and the line in the agent's result,WebOptions), andonDialognotes. One saysonDialog('accept')passes a prompt no text, which Chromium and WebKit answer as an empty string.executors.mdxdescribessystemLog;reference/engine.mdxcarries the newAppLogEntrydoc.- A pointer in
browser.mdx, "Get past confirmation dialogs" inexplore.mdx, and the dialog lines in the app log list indebugging.mdx. - The Playwright and Cypress migration guides name the option. Playwright dismisses an unhandled dialog but accepts a
beforeunload, so its row also gives the handler that matches it exactly. packages/web/README.mdand the consumer skill'ssetup.mdlist the option. The bug-bash config setsweb({ dialogs: 'accept' }), with a note that@e2e-dev/web0.17.0 refuses the key, andexplore.mdandwriting-tests.mddescribe it.writing-tests.mdnow says an unanswered dialog fails withAPP_NOT_OPEN, the code a test sees, where it saidINVALID_STATE.
The issue's other option, holding the dialog open and showing it in the observation so the agent picks OK or Cancel per dialog, is left out. Playwright's click does not return while a dialog is open, and the page can't be read until the dialog closes. That design would mean racing every action against the dialog and handing the agent a synthetic node tree.
onDialog('accept') keeps its current behavior: it passes a prompt no text, which Chromium and WebKit answer as an empty string. Only the policy passes the default text. That keeps this change from altering existing tests.
The policy is not part of the replay cache key. No other engine option is either (viewport, locale, headers; packages/core/src/cache/identity.ts). A recording made under 'accept' that stops reproducing under 'dismiss' is re-recorded, like after any change to what the app does.
Issue
Resolves ENG-963
Verified
Ran it locally: yes
e2e mcpfrom this build, driven by a small MCP client against a local page with a Delete button behindconfirm('Delete Invoice 42?')and a Save button that callsalert('Could not save: server error 500'). It taps Save, then Delete, once per engine setting. The MCPcallresult is the same tool result the agent reads:
--- tap Save (web({ dialogs: 'accept' }))
Tapped #n6.
Test line: await screen.getByRole("button", "Save").tap();
Screen unchanged since revision b4 (re-observed as revision b30, path /); the ids you have stay valid.
System log (not on the screen):
- alert dialog "Could not save: server error 500" opened; accepting it per web({ dialogs: 'accept' })
--- tap Delete (web({ dialogs: 'accept' }))
Tapped #n5.
Test line: await screen.getByRole("button", "Delete").tap();
The screen changed substantially since revision b30. Current screen (revision b32, path /, 3 nodes):
#root document "Invoices"
#n2 heading "Invoices"
#n6 button "Save"
System log (not on the screen):
- confirm dialog "Delete Invoice 42?" opened; accepting it per web({ dialogs: 'accept' })
--- tap Save (web())
APP_NOT_OPEN: unhandled alert dialog: Could not save: server error 500; register a handler with browser.onDialog, or answer every dialog with web({ dialogs: 'accept' }) or web({ dialogs: 'dismiss' })
--- tap Delete (web())
APP_NOT_OPEN: unhandled confirm dialog: Delete Invoice 42?; register a handler with browser.onDialog, or answer every dialog with web({ dialogs: 'accept' }) or web({ dialogs: 'dismiss' })
- testbed, built CLI, a scratch test that taps Save and Delete on that markup and expects the row gone, under
web({ dialogs: 'accept' })with--trace on(the files were deleted afterwards). It passes, andtrace.mdhas both answers under their steps:
## App log
- step 3 · ℹ system: `alert dialog "Could not save: server error 500" opened; accepting it per web({ dialogs: 'accept' })`
- step 4 · ℹ system: `confirm dialog "Delete Invoice 42?" opened; accepting it per web({ dialogs: 'accept' })`
- main against this branch on the same scratch test, captured at
4b1fb17before the app-log and agent changes, which change no CLI output of a passing run:
| main | this PR |
|---|---|
web(): × delete behind a confirm, APP_NOT_OPEN: unhandled confirm dialog: Delete Invoice 42? | web(): same failure, message ends ; register a handler with browser.onDialog, or answer every dialog with web({ dialogs: 'accept' }) or web({ dialogs: 'dismiss' }) |
web({ dialogs: 'accept' }): INVALID_CONFIG, no tests run | web({ dialogs: 'accept' }): ✓ delete behind a confirm |
web({ dialogs: 'ok' }): web({ dialogs }) must be 'accept' or 'dismiss', got another string; a function handler goes to browser.onDialog in the test, exit 2 |
- The video of the passing
'accept'run, from4b1fb17. Nothing on screen changed since. The test takes 0.4 s, so it is short.
https://github.com/user-attachments/assets/41520956-1037-4384-8bc0-042a75e926b2
pnpm bench:abwas not run on this head. The agent change needs the web benchmark's agent suite, whose app port (4280) was held by another checkout's server, and the machine's load average was about 11, too high for timings. The suite replays recorded steps, which never render a tool result, so its behavior and counter sections could not show this change either. On6f0cb67, before the agent change, the web benchmark's two dialog suites (native-dialogs,deferred-dialog) ran the same steps with the same counters on both builds (12 pairs, load 17.4).- Tests:
packages/e2e/tests/integration/explore.test.ts:e2e explorewith a scripted model taps Save (analert) and Ask (aconfirm) on a fixture page underweb({ dialogs: 'accept' }). Each tap's result carries its own dialog line, the alert's tap is not called one with no effect, and Ask's screen showsstatus "Answer" text="accepted". Without the option, the tap's result isAction failed: unhandled confirm dialog: Proceed?; .... With the note turned off inscreen-update.ts, the test fails.packages/e2e/tests/integration/web-dialog-policy.test.ts: a real Chromium run per policy.confirmreturnstrueorfalse,prompt('Name?', 'keep me')returns'keep me'ornull,beforeunloadlets the page go underacceptand keeps it underdismiss, and the report's app log has onesystemline per answered dialog and none for a test'sonDialoghandler.- Unit:
app-log.test.ts(systemLines: cursor, newest five, apart from a full quota),agent-observation.test.ts(each line once, redacted before the cut, a line from before the step left out),agent-screen-update.test.ts(note placement, every rendering, no "no effect" verdict),transcript-compaction.test.ts(an elided screen keeps its note). pnpm check(lint with.t3-tmpexcluded), thee2eunit project (5033 passed), and the agent, MCP, explore, and dialog integration files (33 files) pass.
- A real model was not run: no model key was available here. The explore and MCP checks use a scripted model or none.
Checklist
- Changeset added (
pnpm changeset) for any change to a published package, or the change is testbed, docs, or CI only. - Breaking change: title carries
!, the changeset body names what breaks and what replaces it, and the deprecation warning landed a window earlier (stability policy in CONTRIBUTING.md). - Docs updated in the same PR: the
docs/**/*.mdxpage for the behavior, andskills/e2e/if the skill describes it. - Contract change: emitted
.d.tsreviewed,tests/types/sdk-types.tsupdated; wire change edits the schema and both fixtures. (WebOptions.dialogsandDialogPolicyare pinned inpackages/web/tests/types/dialogs.ts;ExecutorObservation.systemLogis a new optional field.) - Engine contract change (
e2e/engine): changesets fore2e,@e2e-dev/web, and@e2e-dev/mobile. (No contract field changes;AppLogEntry's doc now says asystemline reaches the model, and.changeset/agent-system-log.mdcoverse2eand@e2e-dev/core.)
🤖 Generated with Claude Code