Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

fix(cdp): report missing native dialog handler

ldm051e110896f4f
diff --git a/moli-cdp-smoke/README.md b/moli-cdp-smoke/README.md
index 05870d933..8279f0dcf 100644
--- a/moli-cdp-smoke/README.md
+++ b/moli-cdp-smoke/README.md
@@ -293,14 +293,14 @@ Important gaps:
- Input precision: richer keyboard composition and deeper editable/contenteditable selection defaults remain in scope. Layout-backed single-pointer mouse/touch/tap and raw drag dispatch are covered; Chromium drag interception (`Input.dragIntercepted`), multi-touch dispatch, and mobile/touch emulation remain gaps.
- DOM/handle precision: stronger stale-handle matrix, cross-frame isolated-world handle conversion,
deeper mutation-tree replacement edge cases, and deeper selector/hit-test accuracy.
-- Navigation/lifecycle variants: popup target creation is covered through Target events, Puppeteer `waitForTarget()`, and Playwright `page.expect_popup()`; named popup targets reuse an existing CDP target instead of creating duplicates; reserved `_self` / `_top` / `_parent` popup targets navigate the current page in the current simplified top-level model. `window.open()` now returns a non-null WindowProxy projection. JavaScript dialog protocol shape covers no-dialog rejection plus prompt opening/closing fields. Remaining gaps are full WindowProxy/opener scripting behavior, background popup document load/activation after named-target reuse, confirm/prompt modal return semantics, true script-blocking dialog behavior, sharper `wait_until` edge cases, same-document history entry precision, and target lifecycle edge cases.
+- Navigation/lifecycle variants: popup target creation is covered through Target events, Puppeteer `waitForTarget()`, and Playwright `page.expect_popup()`; named popup targets reuse an existing CDP target instead of creating duplicates; reserved `_self` / `_top` / `_parent` popup targets navigate the current page in the current simplified top-level model. `window.open()` now returns a non-null WindowProxy projection. JavaScript dialogs block the invoking script until an automation client accepts or dismisses them, and prompt return values plus opening/closing protocol fields are covered. Remaining gaps are full WindowProxy/opener scripting behavior, background popup document load/activation after named-target reuse, native browser dialog UI, sharper `wait_until` edge cases, same-document history entry precision, and target lifecycle edge cases.
- Navigation response precision: Puppeteer selector-backed DOM activation completes and updates `page.url()`, while the smoke records whether `waitForNavigation()` exposes the committed document response. `page.goto()` and `page.reload()` response objects are required separately. Coordinate `page.click()` is supported when the server runs with `--layout`; Mock policy still fails explicitly.
- Same-document navigation precision: Puppeteer `page.waitForNavigation()` is now covered for hash-only and History API navigation through renderer-produced `Page.navigatedWithinDocument` events. Remaining precision work is deeper history traversal/back-forward entry parity and Navigation API interception-style same-document reasons.
- Screenshot/layout/emulation: raw full-page/clip/node screenshots and raster-backed `Page.printToPDF` are covered, including base64/stream transfer, pagination, page ranges, orientation, print media, and background control. Header/footer templates, CSS page-size preference, tagged PDFs, document outlines, vector/text-preserving output, richer device-scale behavior, and more accurate layout metrics remain gaps. The Chrome `chrome://inspect` command menu is a separate DevTools-frontend concern and does not advertise Moli's screenshot capability.
- Wider network matrix: broader digest/multi-round proxy auth challenge variants, font/preload resource types, parser-discovered resource interception, and broader response-stage coverage beyond the current page/popup fetch/XHR response-stage smoke.
- Storage/profile depth: cookie delete/clear/domain/path/SameSite, persistent profile writeback, storage partition boundaries, and deeper IndexedDB flows.
- Worker/frame target depth: module-worker target lifecycle, nested DedicatedWorker targets, broader worker exception/debugger coverage, iframe subresource attribution, and future per-frame realm boundaries remain. DedicatedWorker now has first-layer CDP target/runtime/console/lifecycle coverage; SharedWorker has first-layer target/runtime/log/profiler and page-side reuse smoke, but both still need richer error matrices.
-- Puppeteer parity: the default managed-client group covers the common connect/navigation/reload/same-document/evaluate/keyboard-input/DOM-selector-activation/coordinate-click/handle/current-viewport-screenshot/alert-dialog/popup-target/interception path and DedicatedWorker lifecycle, but full-page/clip screenshots, drag interception, confirm/prompt modal return semantics, and richer lifecycle waits remain.
+- Puppeteer parity: the default managed-client group covers the common connect/navigation/reload/same-document/evaluate/keyboard-input/DOM-selector-activation/coordinate-click/handle/current-viewport-screenshot/alert-dialog/popup-target/interception path and DedicatedWorker lifecycle, but full-page/clip screenshots, drag interception, broader dialog edge cases, and richer lifecycle waits remain.
Runner layout:
@@ -351,7 +351,7 @@ Runner layout:
Near-term expansion order:
-1. Deepen popup and dialog fidelity: popup Target linkage is observable by Playwright/Puppeteer, anchor `target="_blank"` now enters the same popup activation path, named target reuse no longer creates duplicate targets at Target-discovery level, reserved current-context targets no longer create bogus popup targets, and JavaScript dialog protocol errors/fields now match Chromium more closely, but `window.open()` still returns `null` instead of a WindowProxy, named-target reuse does not yet drive a full background popup document load, and `confirm()` / `prompt()` emit dialog events but do not block and resume the script with the accepted value.
+1. Deepen popup and dialog fidelity: popup Target linkage is observable by Playwright/Puppeteer, anchor `target="_blank"` now enters the same popup activation path, named target reuse no longer creates duplicate targets at Target-discovery level, reserved current-context targets no longer create bogus popup targets, `window.open()` returns a WindowProxy projection, and automation-controlled JavaScript dialogs block and resume with the handled value. Remaining work includes fuller WindowProxy/opener behavior, complete background popup document loading after named-target reuse, native browser dialog UI, and Chromium's dialog suppression policies.
2. Add more network/resource-type coverage after that, especially font/preload observation, parser-discovered resource interception, proxy auth, and richer auth variants. Stylesheet link / `@import` has Network smoke coverage without requiring a following parser script, the Chromium-derived matrix covers image/media/text-track/XHR body capture, page `fetch()` response-stage pause / continue has a focused smoke, page XHR response-stage covers `Fetch.getResponseBody`, page fetch response-stage covers `Fetch.takeResponseBodyAsStream` / `IO.read`, and server-auth covers successful credentials plus Chromium-compatible `CancelAuth` for page fetch, worker fetch/XHR, configured response-stage continuation, and top-level navigation.
3. Keep low-frequency CDP methods out of this smoke unless they block a real Playwright workflow. Use focused Rust tests for narrow protocol shape regressions and keep each fixture-derived CDP contract as a separate test.
diff --git a/moli-cdp-smoke/moli_cdp_smoke/groups/protocol.py b/moli-cdp-smoke/moli_cdp_smoke/groups/protocol.py
index bae59d002..4d989dc0e 100644
--- a/moli-cdp-smoke/moli_cdp_smoke/groups/protocol.py
+++ b/moli-cdp-smoke/moli_cdp_smoke/groups/protocol.py
@@ -517,6 +517,11 @@ async def _javascript_dialog_protocol_shape(
"default prompt",
"raw Page.javascriptDialogOpening default prompt",
)
+ assert_equal(
+ params.get("hasBrowserHandler"),
+ False,
+ "raw Page.javascriptDialogOpening native browser handler",
+ )
if not isinstance(params.get("frameId"), str) or not params["frameId"]:
raise SmokeError(f"missing prompt frameId in {opening}")
diff --git a/moli-protocol-server/src/protocol_server/tests/websocket.rs b/moli-protocol-server/src/protocol_server/tests/websocket.rs
index ee88566a2..bfc44c718 100644
--- a/moli-protocol-server/src/protocol_server/tests/websocket.rs
+++ b/moli-protocol-server/src/protocol_server/tests/websocket.rs
@@ -6100,8 +6100,9 @@ async fn websocket_cdp_handle_javascript_dialog_prompt_text_resumes_prompt() {
message["sessionId"].as_str() == Some(session_id.as_str())
&& message["method"] == json!("Page.javascriptDialogOpening")
&& message["params"]["defaultPrompt"] == json!("default answer")
+ && message["params"]["hasBrowserHandler"] == json!(false)
}),
- "prompt opening should include defaultPrompt: {observed:#?}"
+ "prompt opening should include defaultPrompt and report that Moli has no native dialog UI: {observed:#?}"
);
observed.extend(
diff --git a/moli-protocol/src/domains/page.rs b/moli-protocol/src/domains/page.rs
index 3ac052d64..a514a756a 100644
--- a/moli-protocol/src/domains/page.rs
+++ b/moli-protocol/src/domains/page.rs
@@ -2787,7 +2787,7 @@ mod producer_tests {
);
assert_eq!(event.dialog_type, "alert");
assert_eq!(event.message, "prepared dialog");
- assert!(event.has_browser_handler);
+ assert!(!event.has_browser_handler);
let installed = conn
.target_page_session_state_for_session(Some("SID-1"))
.expect("target page session state should exist")
diff --git a/moli-protocol/src/domains/page/javascript_dialog.rs b/moli-protocol/src/domains/page/javascript_dialog.rs
index 9d800c609..2e1075deb 100644
--- a/moli-protocol/src/domains/page/javascript_dialog.rs
+++ b/moli-protocol/src/domains/page/javascript_dialog.rs
@@ -134,7 +134,11 @@ fn emit_to_attachment(
url: source_url,
message,
dialog_type,
- has_browser_handler: true,
+ // Moli has no native browser UI capable of presenting or resolving
+ // JavaScript dialogs. CDP clients can still resolve this dialog via
+ // Page.handleJavaScriptDialog; `false` also lets the Chromium
+ // DevTools frontend dismiss it instead of waiting for nonexistent UI.
+ has_browser_handler: false,
default_prompt,
},
));
diff --git a/moli-protocol/src/domains/page/tests/dialog.rs b/moli-protocol/src/domains/page/tests/dialog.rs
index b1c8f89cb..4446c593a 100644
--- a/moli-protocol/src/domains/page/tests/dialog.rs
+++ b/moli-protocol/src/domains/page/tests/dialog.rs
@@ -245,7 +245,7 @@ async fn javascript_dialog_events_round_trip_through_page_domain() {
assert_eq!(opening["sessionId"], json!("SID-1"));
assert_eq!(opening["params"]["type"], json!("alert"));
assert_eq!(opening["params"]["message"], json!("smoke alert"));
- assert_eq!(opening["params"]["hasBrowserHandler"], json!(true));
+ assert_eq!(opening["params"]["hasBrowserHandler"], json!(false));
assert_eq!(opening["params"]["frameId"], json!("TID-1"));
ctx.process_async(json!({