Skip to content

fix(browser): let agents and users answer page alert, confirm and prompt dialogs on their page - #36268

Merged
AmoabaKelvin merged 3 commits into
mainfrom
browser-dialogs-alert-prompt
Oct 30, 2026
Merged

AmoabaKelvin merged 3 commits into
mainfrom
browser-dialogs-alert-prompt

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 10 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​331 $\color{#cf222e}{\Huge{\mathbf{−}}}$​353 $\color{#cf222e}{\Huge{\mathbf{−}}}$​22
Prod 36 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​544 $\color{#cf222e}{\Huge{\mathbf{−}}}$​151 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​393

ELI5

When a web page in Orca's built-in browser pops up an alert, confirm or prompt, Orca now owns that pop-up. It shows it inside Orca, tied to the page that opened it, and agents can read and answer it. Before, Electron showed its own sheet over the whole Orca window. An agent never saw the alert's text, prompt() didn't work at all, and some commands hung for a minute behind an open dialog.

What Changed

Before, verified live on main:

  • alert: agent-browser auto-accepted it over CDP, so the agent never saw the text. Electron's native "Hello alert" sheet then stayed stuck on Orca's main window after the page had already continued, because the first answer wins and the sheet's later click does nothing.
  • confirm: orca eval hung for 60 s with Timed out waiting for the Orca runtime to respond. orca dialog accept was queued behind whatever command was stuck.
  • prompt: it threw prompt() is not supported because Electron replaces window.prompt in every webview frame. orca dialog accept then said No dialog is showing.
  • Scope browser JavaScript dialogs to their page #17577: the native sheet belongs to the whole window, not to the page that asked.

After:

  • One owner. src/main/browser/browser-javascript-dialogs.ts replaces Electron's private -run-dialog listener on every browsing guest (did-attach-webview) and on orca serve pages. It records the open dialog per page and answers through Electron's callback.
  • Users get the dialog through the existing page-prompt framework as a new javascript-dialog kind. It is titled with the origin of the frame that asked, so an embedded frame can't speak as the site, and a prompt has an input with its default text. These dialogs have no timeout and aren't quieted or refused like permission prompts.
  • Agents:
    • While a dialog is open, any page command fails at once with its type and text: A JavaScript confirm is open on this page: "Delete everything?". Answer it with `orca dialog accept --page …` or `orca dialog dismiss --page …`, then retry.
    • A command that opens a dialog returns at once, saying it may already have taken effect. It keeps its queue turn until it finishes, so nothing overtakes it.
    • Commands that were waiting behind it are dropped with "did not run".
    • orca dialog accept [--text] and orca dialog dismiss answer the owner directly instead of going through the queue. An accepted prompt with no --text gets its default text, as in Chrome.
    • agent-browser now runs with AGENT_BROWSER_NO_AUTO_DIALOG=1, so alerts wait to be answered like confirms do.
  • prompt(): the existing guest preload installs a main-world window.prompt that calls the native prompt of a short-lived same-origin about:blank iframe, which Electron leaves alone. A prompt is now a real Chromium dialog, so the owner, CDP and the phone all see it.
  • Phone: answers go through the same owner. The mobile screencast's separate CDP answer path (settleDialog) is removed. The card keeps showing the held dialog when a second frame's dialog is turned away.
  • The skill guide (skill-guides/orca-cli/references/browser.md) lists the dialog commands and the browser_dialog_open / browser_dialog_opened recoveries.

Why

The root cause: no Orca component owned guest JavaScript dialogs. Electron's default handler, agent-browser's CDP auto-answer, the mobile screencast and Orca's direct-CDP eval each acted on the same dialog on their own.

I hook Electron's embedder dialog callback because it is the one place that sees every dialog, whether or not a CDP client is attached, and its answer needs no CDP session. That also avoids the "only the reporting session can answer" problem that #21799 worked around for mobile. A CDP-events-only design would miss dialogs opened before a client attaches, and it would leave the stale native sheet.

I reused the existing page-prompt framework rather than build a new in-pane overlay as the closed community PR #11959 did. That keeps UI, IPC, preload and i18n changes small, and it is how HTTP auth and site-permission prompts already show. Thanks to @dgk-dev for #11959, which first mapped the -run-dialog route.

Linked Issue

Fixes #17577

Visual Proof

The old native sheet can't be captured from a hidden dev build. Before, as live CLI output on main (the native "Hello alert" sheet text was read back through macOS Accessibility after the page had continued):

$ orca click --element e2      # alert('Hello alert')
Clicked e2
$ orca exec --command "dialog status"
{ "hasDialog": false }         # alert text lost; native sheet still on Orca's window
$ orca eval --expression 1+1   # confirm open
Timed out waiting for the Orca runtime to respond.   [60.2s]
$ orca dialog accept --text bob   # prompt
CDP error (Page.handleJavaScriptDialog): No dialog is showing

After:

$ orca click --element e2
The page opened a JavaScript alert: "Hello alert". The command may already have taken effect, so don't repeat it. Answer it with `orca dialog accept --page …` or `orca dialog dismiss --page …`.
$ orca eval --expression 1
A JavaScript confirm is open on this page: "Delete everything?". Answer it with … then retry.   [0.3s]
$ orca dialog accept --text final
Dialog accepted        → page: "prompt: final"

In-app prompt (default text pre-filled) and confirm (OK focused, so Enter accepts):

after-prompt-crop.png
after-confirm-crop.png

Testing

Live on macOS, on a hidden dev build of this branch (ORCA_BACKGROUND_LAUNCH=1) driven by the dev CLI:

  • alert, confirm, prompt through click and through eval: each surfaces its text. Accept, dismiss and accept --text reach the page, and an accepted prompt without text returns its default.
  • No native sheet: the Accessibility sheet count stayed at 0.
  • Prompt from a cross-origin iframe works.
  • Page scoping: with a confirm open on page A, commands on page B run, and dialog accept --page B says no dialog is open.
  • Ordering: in a parallel click + eval, the eval fails fast. A wait interrupted by a delayed alert returns at once.
  • beforeunload still lets navigation through.
  • In-app dialog: answering it in the UI reaches the page. An agent's answer closes it. Enter accepts a confirm.
  • Headless orca serve page: confirm and alert surface and are answerable.

Automated:

  • New browser-javascript-dialogs.test.ts covers the owner.
  • New agent-browser-bridge-javascript-dialog.test.ts covers fail-fast, early answer without overtaking, commands queued behind a dialog being dropped, and SSH-host admission before dialog text is quoted. I watched each case fail without its fix.
  • New screencast case: the phone card keeps the held dialog, and stopping the stream dismisses it.
  • The settlement tests for the removed screencast path are deleted.
  • 71 dependent test files pass locally (664 tests), plus the changed-file quality and React Doctor checks. CI covers the rest.

Not tested on Linux or Windows; nothing here is platform-specific.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

AI Disclosure

Review

Ran review-loop (Codex + Claude) for 4 rounds. Accepted and fixed:

  • orca serve pages had no owner;
  • interrupted commands could be overtaken, and commands queued behind a dialog were never told about it;
  • SSH-host admission was skipped before quoting dialog text, including inside the opened-dialog notification;
  • the agent-activity lease ended early, and leaked when a queued command was revoked;
  • a turned-away nested dialog's CDP close cleared the first dialog and the phone card;
  • tab switch waited behind a blocked command;
  • a dialog opening during session setup went unwatched;
  • dialogs used the top page's origin instead of the asking frame's;
  • unbounded message length;
  • the prompt shim failed in SVG documents;
  • Enter on a confirm chose Cancel.

The fourth round's two findings were one-line fixes, applied after it; there was no fifth round (the loop caps at four).

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

  • Security:

    • Dialog text is page-controlled. It is quoted, capped at 500 characters in agent errors, and only shown to a remote CLI host after that host's guest admission check passes.
    • The prompt shim runs in the page's main world, like the existing window.close guard.
  • Cross-platform: no platform branches. -run-dialog is the same on every OS.

  • Remote / mixed versions: RPC shapes are unchanged: browser.dialogAccept and browser.dialogDismiss still return { accepted }. Older CLIs and phones work unchanged. Error texts are new.

  • Mobile: answers reach the owner through the same RPCs. The card has no text field yet, so a prompt accepted from the phone takes its default text. That is a follow-up.

  • Known limits / follow-ups:

    • prompt() on orca serve offscreen pages still throws, because those windows have no preload.
    • A dialog opened on mousedown leaves agent-browser's logical mouse button down, since its own dialog accept is no longer used.
    • If an agent answers through raw orca exec "dialog accept", Orca's record stays until orca dialog accept or dismiss clears it, or the page navigates.
    • Stopping the last phone viewer still dismisses an open dialog. That is existing behavior: a new CDP session blocks behind an open dialog.
    • Electron's -run-dialog is a private event; Electron has no public hook for this.
  • Overlap: getBrowserJavaScriptDialog and onBrowserJavaScriptDialogOpened are the reusable dialog state for reporting "dialog opened" in action results.

  • To try (needs blessing: new in-app dialog UI and agent dialog behavior): build this branch (worktree ~/orca/workspaces/orca/browser-dialogs, pnpm dev) and open a browser tab on a page with <button onclick="out.textContent=confirm('Delete everything?')">, an alert() and a prompt('Your name?','def') button.

    • Click each button yourself. Orca's own dialog appears, titled with the page's origin; Enter accepts. No macOS sheet appears.
    • From a terminal in that workspace, run orca click --page <id> --element <ref> on the same buttons. The command returns the dialog's text at once, any other command on the page fails fast with it, and orca dialog accept --page <id> --text Ada answers it and closes the in-app dialog.
  • Product question for review: dialogs show in the app-wide prompt modal like HTTP auth and permission prompts, titled with the asking origin. Closed PR fix(browser): scope JavaScript dialogs to their page #11959 drew them inside the page's own pane instead.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 25020bb0-5ab3-477e-89d8-1731e34173c2
Commits

Reviewing files that changed from the base of the PR and between 36db8f8 and 213d702.

Files selected for processing: 1
  • src/renderer/src/components/confirmation-dialog.tsx
Files skipped from review as they are similar to previous changes: 1
  • src/renderer/src/components/confirmation-dialog.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Walkthrough

The browser now presents JavaScript alert, confirm, and prompt dialogs as page prompts. The main process tracks dialogs per browser guest, and browser commands report open dialogs and support direct accept or dismiss actions. Screencast events read dialog state from the shared handler, and stopping a stream dismisses an open dialog. Runtime dialog commands now use the bridge instead of screencast settlement. CLI guidance and localized prompt labels are also updated.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Minimal · up to 213d7

No actionable issue is established for the selected change; it is ready for normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 46.15% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title names the main change: browser JavaScript alert, confirm, and prompt dialogs become answerable by agents and users on the page that opened them. The changeset matches this. It adds page-owne…
Description check Passed The description follows the repository template closely. It has an ELI5, a What Changed section with before and after behavior and mechanism, a Why section that explains the chosen approach over alter…
Linked Issues check Passed Issue #17577 requires page-scoped JavaScript dialog ownership and browser coverage. browser-javascript-dialogs.ts stores dialog state by guest page, derives the requesting frame origin, routes answe…
Out of Scope Changes check Passed The changes support #17577. The page-prompt UI, prompt shim, agent queue handling, direct dialog commands, screencast routing, localization, documentation, and tests implement or verify page-scoped di…
Full details: Title check

Explanation

The title names the main change: browser JavaScript alert, confirm, and prompt dialogs become answerable by agents and users on the page that opened them. The changeset matches this. It adds page-owned dialog handling, a dialog page-prompt kind, and agent dialog accept and dismiss behavior. The title uses the conventional fix(browser) prefix and is specific. It is 94 characters, slightly above a short title, but still one clear sentence.

Full details: Description check

Explanation

The description follows the repository template closely. It has an ELI5, a What Changed section with before and after behavior and mechanism, a Why section that explains the chosen approach over alternatives, a Linked Issue (Fixes #17577), Visual Proof with before and after CLI output and screenshots, Testing with manual macOS steps and automated test coverage, an AI Disclosure heading, Review notes, the upstream boundary checkbox, and Notes covering security, cross-platform, SSH, mobile, and compatibility. Some checklist items remain unchecked, and the AI Disclosure section is empty, but the template allows empty AI Disclosure for internal contributors. The description is thorough and mostly complete.

Full details: Linked Issues check

Explanation

Issue #17577 requires page-scoped JavaScript dialog ownership and browser coverage. browser-javascript-dialogs.ts stores dialog state by guest page, derives the requesting frame origin, routes answers to the owning dialog, and preserves the first dialog when a second request occurs. browser-javascript-dialogs.test.ts, agent bridge tests, and screencast tests cover ownership, answers, page reporting, and multi-page behavior.

Full details: Out of Scope Changes check

Explanation

The changes support #17577. The page-prompt UI, prompt shim, agent queue handling, direct dialog commands, screencast routing, localization, documentation, and tests implement or verify page-scoped dialog handling. No unrelated change is demonstrated.

Full details: Docstring Coverage

Explanation

Docstring coverage is 46.15% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 13 functions across 29 files.

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 3


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6b6817ff-8a88-4ebe-b12f-2421d3969f58
Commits

Reviewing files that changed from the base of the PR and between b67c525 and e04d96d.

Files selected for processing: 46
  • skill-guides/orca-cli/references/browser.md
  • src/cli/bundled-skill-guides.ts
  • src/main/browser/agent-browser-bridge-javascript-dialog.test.ts
  • src/main/browser/agent-browser-bridge-queue.ts
  • src/main/browser/agent-browser-bridge-utility-commands.ts
  • src/main/browser/agent-browser-process-environment.ts
  • src/main/browser/browser-javascript-dialogs.test.ts
  • src/main/browser/browser-javascript-dialogs.ts
  • src/main/browser/browser-page-prompts.ts
  • src/main/browser/browser-screencast-cdp-events.ts
  • src/main/browser/browser-screencast-dialog-settlement.test.ts
  • src/main/browser/browser-screencast-lifecycle.test.ts
  • src/main/browser/browser-screencast-live-frame-allocation.test.ts
  • src/main/browser/browser-screencast-stream-types.ts
  • src/main/browser/browser-screencast-stream.test.ts
  • src/main/browser/browser-screencast-stream.ts
  • src/main/browser/offscreen-browser-backend.ts
  • src/main/runtime/browser-dialog-settlement.test.ts
  • src/main/runtime/browser-dialog-settlement.ts
  • src/main/runtime/browser/browser-commands.ts
  • src/main/runtime/browser/browser-dialogs.ts
  • src/main/runtime/browser/browser-screencast-contracts.ts
  • src/main/runtime/browser/browser-screencasts.test.ts
  • src/main/runtime/browser/browser-screencasts.ts
  • src/main/window/createMainWindow.test.ts
  • src/main/window/main-window-webview-security.test.ts
  • src/main/window/main-window-webview-security.ts
  • src/preload/browser-window-close.ts
  • src/preload/browser-window-prompt-installation.ts
  • src/renderer/src/components/browser-pane/browser-javascript-dialog-prompt.ts
  • src/renderer/src/components/browser-pane/browser-page-prompts.tsx
  • src/renderer/src/components/confirmation-dialog-context.ts
  • src/renderer/src/components/confirmation-dialog.tsx
  • src/renderer/src/i18n/locales/de.json
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/es.json
  • src/renderer/src/i18n/locales/fr.json
  • src/renderer/src/i18n/locales/ja.json
  • src/renderer/src/i18n/locales/ko.json
  • src/renderer/src/i18n/locales/pt.json
  • src/renderer/src/i18n/locales/ru.json
  • src/renderer/src/i18n/locales/tr.json
  • src/renderer/src/i18n/locales/zh-Hant.json
  • src/renderer/src/i18n/locales/zh.json
  • src/shared/browser-javascript-dialog.ts
  • src/shared/browser-page-prompt.ts
Files with no reviewable changes: 5
  • src/main/browser/browser-screencast-dialog-settlement.test.ts
  • src/main/browser/browser-screencast-stream-types.ts
  • src/main/runtime/browser-dialog-settlement.ts
  • src/main/runtime/browser/browser-screencasts.ts
  • src/main/runtime/browser-dialog-settlement.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9b0682cb-afe2-499a-b0f9-ce2bcecd6950
Commits

Reviewing files that changed from the base of the PR and between e04d96d and 36db8f8.

Files selected for processing: 2
  • src/main/browser/agent-browser-bridge-queue.ts
  • src/renderer/src/components/browser-pane/browser-javascript-dialog-prompt.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

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.

Scope browser JavaScript dialogs to their page

1 participant