Skip to content

Browser tools: report a dialog that an input action opens after the action resolved - #350301

Draft
Bryan Chen (bryanchen-d) wants to merge 2 commits into
mainfrom
copilot/vscode/browser-dialog-settle
Draft

Bryan Chen (bryanchen-d) wants to merge 2 commits into
mainfrom
copilot/vscode/browser-dialog-settle

Conversation

@bryanchen-d

@bryanchen-d Bryan Chen (bryanchen-d) commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #350285

chat - browser tools › click and typing tools can handle dialogs in main, opaque, and nested frames has failed intermittently in Linux / Electron (extension host) since #349555. The assertion that fails is clicked.includes('Active alert dialog:'), right after click_element on a button whose onclick calls alert(). In each failure the snapshot shows the click landed, because the button or its frame is [active], but the result doesn't report the dialog. See the issue for the failing runs.

Cause

PlaywrightTab.safeRunAgainstPage races the action against a dialog opening. A Playwright click can resolve before the page has run the click's handlers, which means before alert() is called. The action then completed without a dialog, and the summary was built before the dialog reached the browser view's dialog queue. For an agent, the click looks like it opened nothing, and its next action fails with "Cannot perform action while a dialog is open". This was inferred from the code and the failing outputs. The issue has the full reasoning.

Fix

Actions that tools run through PlaywrightService (invokeFunction, invokeFunctionRaw) now pass reportTriggeredDialogs. When an action has completed, safeRunAgainstPage waits for one evaluation in each frame before reporting the action complete, and it still races the dialog opening:

  • Each evaluation runs after the input the action sent. While a dialog is pending, evaluations in the browser view wait for it. So if the input opens a dialog, the dialog wins the race and is reported the same way as a dialog that opened during the action.
  • The wait is capped at 1 s, so a frame that never answers doesn't hold the action. If a dialog opens, the pending wait is cancelled along with the action.
  • Cost for actions that open no dialog: one parallel no-op evaluation per frame, with no fixed delay. The summary's own snapshot and title calls don't wait, and neither do dialog or file-chooser replies.

The integration test is unchanged.

Validation

  • New unit tests in playwrightTab.test.ts:
    • A dialog that opens only once the page is next evaluated is reported as DialogInterruptedError, and it shows up in the summary.
    • An action without a dialog waits for exactly one evaluation per frame.
    • Without the fix, both tests fail: the action returns 'clicked' and makes 0 evaluations.
  • CI loop: a temporary commit looped the integration test 40 times in Linux / Electron (extension host). Over two runs it passed 80 of 80, in this run and its rerun. That commit has been dropped.

Authored with Copilot

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Resuming deferred results restarts the frame-settling wait, so a frame that exceeds the polling timeout can cause endless deferrals even after the original callback and wait have completed.

1 open issue
What changed in this PR

This PR addresses #350285 by making browser tool actions report dialogs that open just after the action resolves, rather than leaving the next action blocked unexpectedly.

Changes:

  • Adds an optional, cancellable frame-evaluation wait capped at one second and enables it for Playwright tool execution.
  • Adds unit coverage for delayed dialogs and actions that open no dialog.
  • Temporarily repeats the existing dialog integration scenario 40 times for CI validation.
File Description
src/​vs/​platform/​browserView/​test/​node/​playwrightTab.test.ts Tests delayed-dialog reporting and per-frame evaluation.
src/​vs/​platform/​browserView/​node/​playwrightTab.ts Adds the bounded wait for action-triggered dialogs.
src/​vs/​platform/​browserView/​node/​playwrightService.ts Enables dialog reporting for tool execution.
extensions/​vscode-api-tests/​src/​singlefolder-tests/​browser.tools.test.ts Repeats the dialog scenario for temporary stress validation.

Review effort: Balanced

…ction resolved

A click can resolve before the page runs its handlers, for example before an onclick calls alert(). The tool then reported the click without the dialog, and the agent's next action failed because a dialog was open. After an action run for a tool, wait for one evaluation per frame, capped at 1 s, while still racing the dialog opening, so a dialog the input opened is reported with the action. Evaluations wait for pending dialogs, so the dialog wins that race.

Fixes #350285

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…esult

Resuming re-runs the stored result through the same path, which restarted the frame wait each time. A frame that answered slower than short resume timeouts could keep returning deferred results after the work finished. The wait already ran, or was cut short by the dialog it reported, on the first call.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bryanchen-d
Bryan Chen (bryanchen-d) force-pushed the copilot/vscode/browser-dialog-settle branch from 6a4ecb3 to 873272a Compare November 25, 2026 05:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the delayed-dialog reporting change.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Browser tools: click on an alert() button can return before the dialog is reported

2 participants