Repository navigation
Conversation
📝 WalkthroughWalkthroughThe change adds browser JavaScript dialog support across Electron guests, BrowserManager, IPC, preload APIs, and the renderer. Dialogs are intercepted, normalized, length-limited, tracked, and routed to authorized renderers. The renderer provides alert, confirm, and prompt controls. Automation commands respond directly to pending dialogs before using the existing fallback. Tests cover routing, lifecycle cleanup, cancellation, Unicode-safe truncation, IPC behavior, renderer state, and dialog interactions. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (7)
src/main/browser/browser-javascript-dialog-controller.test.ts (1)
34-110: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd coverage for
-cancel-dialogsand fordisposewith a pending dialog.The tests cover interception, CDP resolution, response, and truncation. Two deliberate behaviors stay untested:
-cancel-dialogsmust callonClosedand must not invoke the Chromium callback.disposewith a pending dialog must invoke the callback with(false, '')so the guest page does not stay blocked.Both are cheap to assert with the existing
createGuesthelper.💚 Proposed tests
it('clears scoped UI when Chromium cancels dialogs', () => { const { events, guest } = createGuest() const callback = vi.fn() const onClosed = vi.fn() installBrowserJavaScriptDialogController(guest, { onOpened: vi.fn(), onClosed }) events.emit('-run-dialog', dialogInfo(), callback) events.emit('-cancel-dialogs') expect(onClosed).toHaveBeenCalledOnce() expect(callback).not.toHaveBeenCalled() }) it('rejects a pending dialog on dispose', () => { const { events, guest } = createGuest() const callback = vi.fn() const controller = installBrowserJavaScriptDialogController(guest, { onOpened: vi.fn(), onClosed: vi.fn() }) events.emit('-run-dialog', dialogInfo(), callback) controller.dispose() expect(callback).toHaveBeenCalledWith(false, '') })src/main/browser/browser-manager.ts (1)
1232-1248: 🔒 Security & Privacy | 🔵 Trivial | 💤 Low valueDocument that
respondToPendingJavaScriptDialogskips renderer ownership validation.
respondToJavaScriptDialogvalidatesrendererWebContentsIdByTabIdbefore delegating. This method performs no such check, so it answers the pending dialog for any page id the caller names. The only current caller isAgentBrowserBridge, which runs in the main process, so the trust boundary holds today. Add a short doc comment so a future IPC handler is not wired to it directly.♻️ Proposed comment
+ // Why: trusted main-process automation only (agent-browser). Renderer IPC must use + // respondToJavaScriptDialog, which validates page ownership first. respondToPendingJavaScriptDialog(src/main/browser/browser-manager.test.ts (1)
179-203: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick winAdd a
file://frame case to cover the only path that forwards a frame URL.
toJavaScriptDialogEventusesdialog.frameUrlwhenframeOriginisfile://, and passes it tosafeOrigin. This fixture always sendsorigin: 'https://example.com', so the assertion at Line 203 never exercises that branch. Thefile://branch is the one place where a full URL, including its query, reaches the sanitizer. Add a second emission withframe: { origin: 'file://', url: 'file:///tmp/page.html?token=secret' }and assert the forwardedorigincontains no query.src/main/ipc/browser.test.ts (2)
212-237: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDerive the oversize length from the shared constant.
The test hardcodes
4_097. IfBROWSER_JAVASCRIPT_DIALOG_PROMPT_MAX_CHARSchanges, this test still passes but no longer exercises the boundary.♻️ Proposed refactor
- promptText: 'x'.repeat(4_097) + promptText: 'x'.repeat(BROWSER_JAVASCRIPT_DIALOG_PROMPT_MAX_CHARS + 1)Add the import:
import { BROWSER_JAVASCRIPT_DIALOG_PROMPT_MAX_CHARS } from '../../shared/browser-javascript-dialog'
173-210: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider adding an authorization negative case.
The tests cover the happy path and the length limit. They do not cover an untrusted sender. A regression that drops the
isTrustedBrowserRenderercheck in either handler would go undetected. Add a case with a sender whosegetType()returns'webview'and assertnullandfalse.src/renderer/src/components/browser-pane/use-browser-javascript-dialog.test.tsx (1)
59-90: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider covering the page-id filter branch.
Both tests use
page-1only. The hook ignores opened and closed events whosebrowserPageIddoes not match. That branch prevents one worktree pane from rendering another page's dialog, and it is untested. Add a case that emits an event forpage-2and assertsresult.current.dialogstaysnull.src/renderer/src/components/browser-pane/browser-javascript-dialog-overlay.test.tsx (1)
44-92: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider covering the
busybranch.The overlay ignores Enter and Escape while
busyis true and disables both buttons. No test asserts that. A regression that drops thebusyguard would allow a duplicate response for the same dialog. Add a case that renders withbusyand assertsonRespondis not called after a key press.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: b45e5558-fad2-47de-bfcf-70d9d031b57b
📥 Commits
Reviewing files that changed from the base of the PR and between 16c5526 and f2ee24e60f743b29aaedd3f8e834f6f5d9e3e2f7.
📒 Files selected for processing (18)
src/main/browser/agent-browser-bridge.test.tssrc/main/browser/agent-browser-bridge.tssrc/main/browser/browser-javascript-dialog-controller.test.tssrc/main/browser/browser-javascript-dialog-controller.tssrc/main/browser/browser-manager.test.tssrc/main/browser/browser-manager.tssrc/main/ipc/browser.test.tssrc/main/ipc/browser.tssrc/preload/api-types.tssrc/preload/index.tssrc/renderer/src/components/browser-pane/BrowserPane.tsxsrc/renderer/src/components/browser-pane/browser-javascript-dialog-overlay.test.tsxsrc/renderer/src/components/browser-pane/browser-javascript-dialog-overlay.tsxsrc/renderer/src/components/browser-pane/use-browser-javascript-dialog.test.tsxsrc/renderer/src/components/browser-pane/use-browser-javascript-dialog.tssrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/web/web-preload-api.tssrc/shared/browser-javascript-dialog.ts
Greptile SummaryReplaces Electron's app-global native
Confidence Score: 4/5Safe to merge; the two findings are edge-case style concerns that do not affect dialog blocking semantics, data integrity, or security boundaries. The core interception mechanism, callback lifecycle, renderer ownership checks, UUID-gated responses, and teardown path are all implemented correctly and covered by tests. Two minor issues were found: boundDialogText can split a surrogate pair when an emoji spans the truncation boundary, and getJavaScriptDialog carries a redundant state mutation that is surprising in a getter. Files Needing Attention: browser-javascript-dialog-controller.ts (surrogate-pair truncation) and browser-manager.ts (getJavaScriptDialog side effect).
|
| Filename | Overview |
|---|---|
| src/main/browser/browser-javascript-dialog-controller.ts | New controller that intercepts Electron's internal -run-dialog event; handles dispose, CDP coordination, and prompt text bounding — but boundDialogText uses UTF-16 length, which can split surrogate pairs at the truncation boundary. |
| src/main/browser/browser-manager.ts | Integrates dialog controller lifecycle into guest registration/cleanup; getJavaScriptDialog carries a hidden state mutation (sets javascriptDialogPageIdByGuestId) that is benign but surprising for a getter. |
| src/main/ipc/browser.ts | Adds two IPC handlers with proper renderer trust checks, ownership verification, and prompt-text length guard before forwarding to BrowserManager. |
| src/main/browser/agent-browser-bridge.ts | Tries BrowserManager-owned dialog first (fast path) before launching agent-browser; fallback is preserved correctly. |
| src/renderer/src/components/browser-pane/use-browser-javascript-dialog.ts | Hook wires IPC subscriptions before issuing the hydration query and uses an eventRevision counter to correctly discard stale query results when an event arrives concurrently. |
| src/renderer/src/components/browser-pane/browser-javascript-dialog-overlay.tsx | New scoped overlay with accessible roles, aria-modal, keyboard handling (Enter/Escape), and focus management; renders inside the browser viewport, not a document-level portal. |
Reviews (1): Last reviewed commit: "fix(browser): scope JavaScript dialogs t..." | Re-trigger Greptile
Harden callback resolution, focus containment, Unicode bounds, IPC authorization, localization, and regression coverage.
|
Updated onto current
Validation on current main: 7 focused test files / 198 tests passed; root typecheck passed; focused oxlint and formatting passed; localization catalog verification passed. |
f2ee24e to
33bf754
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/browser/browser-javascript-dialog-controller.ts (1)
59-62: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueCondense this implementation comment.
Keep the non-obvious Electron internal-event rationale in one concise line. Do not describe the event flow.
As per coding guidelines, comments must be concise, limited to non-obvious information, and preferably one line.
Source: Coding guidelines
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: f1785844-a55f-4d6f-af5f-0a76512fbdde
📥 Commits
Reviewing files that changed from the base of the PR and between f2ee24e60f743b29aaedd3f8e834f6f5d9e3e2f7 and 33bf754.
📒 Files selected for processing (6)
src/main/browser/agent-browser-bridge.test.tssrc/main/browser/agent-browser-bridge.tssrc/main/browser/browser-javascript-dialog-controller.test.tssrc/main/browser/browser-javascript-dialog-controller.tssrc/main/browser/browser-manager.test.tssrc/main/browser/browser-manager.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- src/main/browser/browser-manager.test.ts
- src/main/browser/agent-browser-bridge.test.ts
- src/main/browser/browser-manager.ts
- src/main/browser/agent-browser-bridge.ts
Summary
alert/confirm/promptsheets for managed browser guests with an overlay rendered inside the originating browser page.orca dialog accept|dismiss --page ... --worktree ...now resolves an already-pending scoped dialog directly, with the existing agent-browser path retained as fallback.Screenshots
The page is dimmed only inside its browser viewport; Orca's worktree and browser chrome remain usable.
Manual QA also switched to a sibling terminal/browser surface while the alert was pending: the overlay disappeared with its originating page and returned when that page was selected again. CLI acceptance completed in 148 ms without starting an agent-browser process, and the page observed the accepted result.
Testing
pnpm lintpnpm typecheckpnpm testpnpm buildFocused validation on current
origin/main:The full local suite was also exercised. It reached 41,919 passing tests but retained 6 failures in pre-existing PTY/shell-ready suites under a scrubbed test environment; none overlap this change. Re-running the PTY suite against the PR candidate passed all 400 tests, while one existing live-zsh non-ASCII-path case remained environment-sensitive. The dialog-focused suites are green.
AI Review Report
Reviewed the complete main/preload/renderer path and the pinned Electron 43.1.0 implementation. The review specifically checked:
The review flagged that the initial CLI fallback could block during agent-browser session startup. The implementation now attempts the pending BrowserManager dialog first and keeps agent-browser only as the fallback; regression tests cover both paths.
Cross-platform review covered macOS, Linux, and Windows. The overlay has no platform-specific paths, shell behavior, or modifier labels. Enter/Escape behavior is platform-neutral. The only Electron-specific dependency is the internal
-run-dialogevent used by the project's pinned Electron version; tests cover listener replacement, restoration, cancellation, and callback behavior.Security Audit
No security follow-up is required.
Notes
Electron does not expose a public JavaScript-dialog interception API. This uses its internal
-run-dialogcontract, which is explicitly typed by Electron and verified against the pinned runtime. If Electron changes that internal contract during a future upgrade, the controller tests should fail before release.