Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
test(cdp): cover Worker interrupt routing
ldm0897db5964cf5
diff --git a/moli-cdp-smoke/README.md b/moli-cdp-smoke/README.mdindex 1ff0768fa..1aafff13d 100644--- a/moli-cdp-smoke/README.md+++ b/moli-cdp-smoke/README.md@@ -129,7 +129,7 @@ Covered well:response/event crossover, foreign flattened and legacy session rejection,and staged peer-disconnect isolation.- Raw CDP websocket command flow for `Runtime.evaluate(awaitPromise=true)` resolving page `fetch()`, timer-triggered `fetch()`, and WebSocket echo work without any follow-up client command; emitted `Runtime.executionContextCreated.uniqueId` round-tripping through DevTools-shaped `Runtime.evaluate` and `Runtime.callFunctionOn`; Chromium-calibrated pre-commit navigation suspension where DOM/Runtime/Debugger main-thread commands wait while `Performance.getMetrics`, `Runtime.terminateExecution`, and browser commands remain dispatchable; `Debugger.pause` responding before `Debugger.paused`, interrupting an in-flight `Runtime.evaluate`, and resuming that evaluation; commands queued behind a winning `Debugger.resume` completing through normal owner dispatch rather than synthetic cancellation; deterministic nested-function `Debugger.stepOut` response/resumed/caller-pause ordering; browser-global Tracing ownership across independent browser/page WebSocket frontends, including exactly one response for a synchronously completed start and the stop-before-start-ack `end response -> start error -> data -> complete` sequence; shared worker target discovery through `Target.getTargets`, worker-session `Runtime.executionContextCreated` / console log replay, and `Profiler.enable` / `Profiler.start` / `Profiler.stop` through `Target.setAutoAttach`; plus Chromium-calibrated DedicatedWorker target creation/update/attach ordering, exact worker-isolate Runtime/Console routing, `Inspector.workerScriptLoaded`, terminate, and owner-navigation cleanup.-- The default raw `inspector-routing` group is the executable DevToolsSession boundary matrix. It covers per-session Main/IO FIFO and exactly-once completion, IO preemption of non-yielding JavaScript, all 13 methods in Chromium 147's `ShouldSendOnIO`, normal debugger-pause pumping of one mixed V8/Page/DOM Main receiver, instrumentation-pause IO-only behavior, navigation replacement, auxiliary-session detach, BrowserContext teardown with interrupts in flight, and `Page.crash`. Every scenario runs in an isolated target and records its Chromium-derived contract.+- The default raw `inspector-routing` group is the executable DevToolsSession boundary matrix. It covers per-session Main/IO FIFO and exactly-once completion, IO preemption of non-yielding JavaScript, DedicatedWorker and SharedWorker interrupt overtaking plus FIFO recovery, all 13 methods in Chromium 147's `ShouldSendOnIO`, normal debugger-pause pumping of one mixed V8/Page/DOM Main receiver, instrumentation-pause IO-only behavior, navigation replacement, auxiliary-session detach, BrowserContext teardown with interrupts in flight, and `Page.crash`. Every scenario runs in an isolated target and records its Chromium-derived contract.- The focused raw `agent-episode` group copies the recorded RL`Runtime.evaluate(awaitPromise=true)` observe/fill/click path. It requires theaction response before destructive cross-document realm events, observes only@@ -330,6 +330,9 @@ MOLI_INSPECTOR_ROUTING_SCENARIOS=raw_cdp_active_javascript_main_io_lane_matrix \MOLI_INSPECTOR_ROUTING_SCENARIOS=raw_cdp_nested_v8_main_receiver_matrix,raw_cdp_nested_non_v8_main_receiver_matrix \uv run moli-cdp-smoke --group inspector-routing++MOLI_INSPECTOR_ROUTING_SCENARIOS=raw_cdp_dedicated_worker_active_javascript_interrupt,raw_cdp_shared_worker_active_javascript_interrupt \+ uv run moli-cdp-smoke --group inspector-routing```The Chromium 147 IO catalog exercised by the complete group is:@@ -360,7 +363,8 @@ uv run moli-cdp-smoke \The complete `inspector-routing` group was calibrated on 2026-08-16 againstthe local Chromium build `Chrome/147.0.7709.0`. Point the same command at aChromium remote-debugging endpoint to re-run the oracle before changing a-routing contract:+routing contract. The two Worker active-JavaScript interrupt regressions were+also cross-checked on 2026-08-18 against `Chromium/145.0.7632.116`:```bashuv run moli-cdp-smoke \diff --git a/moli-cdp-smoke/moli_cdp_smoke/groups/inspector_routing.py b/moli-cdp-smoke/moli_cdp_smoke/groups/inspector_routing.pyindex 663a40a86..882139a15 100644--- a/moli-cdp-smoke/moli_cdp_smoke/groups/inspector_routing.py+++ b/moli-cdp-smoke/moli_cdp_smoke/groups/inspector_routing.py@@ -39,6 +39,18 @@ async def run_inspector_routing_group(client, page, fixture, results),),+ (+ "raw_cdp_dedicated_worker_active_javascript_interrupt",+ lambda client, page: _worker_active_javascript_interrupt(+ client, page, fixture, results, target_type="worker"+ ),+ ),+ (+ "raw_cdp_shared_worker_active_javascript_interrupt",+ lambda client, page: _worker_active_javascript_interrupt(+ client, page, fixture, results, target_type="shared_worker"+ ),+ ),("raw_cdp_debugger_io_catalog_during_active_javascript",lambda client, page: _debugger_io_catalog_during_active_javascript(@@ -370,6 +382,297 @@ for (;;) {}""")+async def _worker_active_javascript_interrupt(+ client: RawCdpClient,+ page: InspectorRoutingPage,+ fixture: str,+ results: list[dict[str, Any]],+ *,+ target_type: str,+) -> None:+ if target_type == "worker":+ kind = "dedicated_worker"+ label = "DedicatedWorker"+ worker_path = "/worker.js?inspector-routing-active"+ auto_attach_session_id = page.primary_session_id+ create_source = f"""+ new Promise((resolve, reject) => {{+ const worker = new Worker({json.dumps(fixture + worker_path)}, {{+ name: 'inspector-routing-active-worker',+ }});+ globalThis.__inspectorRoutingWorker = worker;+ const timer = setTimeout(+ () => reject(new Error('DedicatedWorker ready timeout')),+ 5000,+ );+ worker.onmessage = event => {{+ if (event.data && event.data.echoed === '__inspector_routing_worker_ready__') {{+ clearTimeout(timer);+ resolve(true);+ }}+ }};+ worker.onerror = event => {{+ clearTimeout(timer);+ reject(new Error(event.message || 'DedicatedWorker failed'));+ }};+ worker.postMessage('__inspector_routing_worker_ready__');+ }})+ """+ elif target_type == "shared_worker":+ kind = "shared_worker"+ label = "SharedWorker"+ worker_path = "/shared-worker.js?inspector-routing-active"+ auto_attach_session_id = None+ create_source = f"""+ new Promise((resolve, reject) => {{+ const worker = new SharedWorker(+ {json.dumps(fixture + worker_path)},+ 'inspector-routing-active-shared-worker',+ );+ globalThis.__inspectorRoutingSharedWorker = worker;+ const timer = setTimeout(+ () => reject(new Error('SharedWorker ready timeout')),+ 5000,+ );+ worker.port.onmessage = event => {{+ if (event.data && event.data.ready === true) {{+ clearTimeout(timer);+ resolve(true);+ }}+ }};+ worker.port.start();+ worker.port.postMessage({{kind: 'ready'}});+ }})+ """+ else:+ raise AssertionError(f"unsupported Worker target type: {target_type}")++ scenario_name = f"raw_cdp_{kind}_active_javascript_interrupt"+ await _reset_witness(fixture)+ auto_attach_id = await client.send(+ "Target.setAutoAttach",+ {+ "autoAttach": True,+ "waitForDebuggerOnStart": False,+ "flatten": True,+ "filter": [+ {"type": target_type, "exclude": False},+ {"exclude": True},+ ],+ },+ session_id=auto_attach_session_id,+ )+ await client.recv_until_id(auto_attach_id, timeout=5)++ create_id = await client.send(+ "Runtime.evaluate",+ {+ "expression": create_source,+ "awaitPromise": True,+ "returnByValue": True,+ },+ session_id=page.primary_session_id,+ )++ worker_session_id: str | None = None+ worker_target_id: str | None = None+ create_response: dict[str, Any] | None = None+ creation_seen: list[dict[str, Any]] = []+ deadline = asyncio.get_running_loop().time() + 10+ while create_response is None or worker_session_id is None:+ remaining = deadline - asyncio.get_running_loop().time()+ if remaining <= 0:+ raise SmokeError(+ f"timed out creating auto-attached {label}; "+ f"response={create_response} session={worker_session_id} "+ f"seen={creation_seen[-20:]}"+ )+ message = await asyncio.wait_for(client.recv(), timeout=remaining)+ creation_seen.append(message)+ if message.get("id") == create_id:+ create_response = message+ if message.get("method") != "Target.attachedToTarget":+ continue+ params = message.get("params", {})+ target_info = params.get("targetInfo", {})+ if target_info.get("type") != target_type:+ continue+ target_url = target_info.get("url")+ if not isinstance(target_url, str) or worker_path not in target_url:+ continue+ session_id = params.get("sessionId")+ target_id = target_info.get("targetId")+ if not isinstance(session_id, str) or not session_id:+ raise SmokeError(f"{label} attach event had no session id: {message}")+ if not isinstance(target_id, str) or not target_id:+ raise SmokeError(f"{label} attach event had no target id: {message}")+ worker_session_id = session_id+ worker_target_id = target_id++ assert create_response is not None+ assert worker_session_id is not None+ assert worker_target_id is not None+ if "error" in create_response:+ raise SmokeError(f"creating {label} failed: {create_response}")+ assert_equal(+ create_response.get("result", {}).get("result", {}).get("value"),+ True,+ f"{label} ready result",+ )++ runtime_enable_id = await client.send(+ "Runtime.enable",+ session_id=worker_session_id,+ )+ await client.recv_until_id(runtime_enable_id, timeout=5)++ busy_source = f"""(() => {{+ const xhr = new XMLHttpRequest();+ xhr.open('GET', {json.dumps(fixture + '/inspector-routing-witness/entered')}, false);+ xhr.send();+ globalThis.__inspectorRoutingWorkerLoopEntered =+ (globalThis.__inspectorRoutingWorkerLoopEntered || 0) + 1;+ for (;;) {{}}+}})()"""+ busy_id = await client.send(+ "Runtime.evaluate",+ {"expression": busy_source},+ session_id=worker_session_id,+ )+ await _wait_for_witness(fixture, expected_count=1)++ follower_one_id = await client.send(+ "Runtime.evaluate",+ {+ "expression": "(globalThis.__inspectorRoutingWorkerOrder ??= []).push('f1')",+ "returnByValue": True,+ },+ session_id=worker_session_id,+ )+ follower_two_id = await client.send(+ "Runtime.evaluate",+ {+ "expression": "globalThis.__inspectorRoutingWorkerOrder.push('f2')",+ "returnByValue": True,+ },+ session_id=worker_session_id,+ )+ blocked_ids = {busy_id, follower_one_id, follower_two_id}+ observed = await _recv_for(client, 0.2)+ early = [message for message in observed if message.get("id") in blocked_ids]+ if early:+ raise SmokeError(+ f"{label} Runtime.evaluate must not interrupt active JavaScript: "+ f"{early}"+ )++ terminate_id = await client.send(+ "Runtime.terminateExecution",+ session_id=worker_session_id,+ )+ expected_ids = blocked_ids | {terminate_id}+ responses, during_interrupt = await _recv_responses(+ client,+ expected_ids,+ timeout=10,+ )+ observed.extend(during_interrupt)+ observed.extend(await _recv_for(client, 0.1))++ for message_id in expected_ids:+ count = sum(message.get("id") == message_id for message in observed)+ assert_equal(+ count,+ 1,+ f"exactly one {label} Inspector response for id {message_id}",+ )+ terminate_response = responses[terminate_id]+ if "error" in terminate_response:+ raise SmokeError(+ f"Runtime.terminateExecution failed to interrupt {label}: "+ f"{terminate_response}"+ )+ assert_equal(+ terminate_response.get("result"),+ {},+ f"{label} Runtime.terminateExecution result",+ )+ busy_response = responses[busy_id]+ if "error" not in busy_response and not isinstance(+ busy_response.get("result", {}).get("exceptionDetails"), dict+ ):+ raise SmokeError(+ f"terminated {label} Runtime.evaluate did not report termination: "+ f"{busy_response}"+ )+ for message_id, expected_value in (+ (follower_one_id, 1),+ (follower_two_id, 2),+ ):+ response = responses[message_id]+ if "error" in response:+ raise SmokeError(f"{label} follower failed after termination: {response}")+ assert_equal(+ response.get("result", {}).get("result", {}).get("value"),+ expected_value,+ f"{label} follower {message_id} value",+ )++ response_order = [+ message["id"] for message in observed if message.get("id") in expected_ids+ ]+ expected_response_order = [+ terminate_id,+ busy_id,+ follower_one_id,+ follower_two_id,+ ]+ if response_order != expected_response_order:+ raise SmokeError(+ f"{label} interrupt response must overtake the active evaluation before "+ "DontInterrupt followers resume in FIFO order: "+ f"expected={expected_response_order} actual={response_order}"+ )++ recovery_id = await client.send(+ "Runtime.evaluate",+ {+ "expression": "JSON.stringify({loop: __inspectorRoutingWorkerLoopEntered, order: __inspectorRoutingWorkerOrder})",+ "returnByValue": True,+ },+ session_id=worker_session_id,+ )+ recovery, _ = await client.recv_until_id(recovery_id, timeout=5)+ assert_equal(+ json.loads(recovery.get("result", {}).get("result", {}).get("value", "null")),+ {"loop": 1, "order": ["f1", "f2"]},+ f"{label} active-JS interrupt recovery state",+ )+ record_contract(+ results,+ scenario_name,+ contract=(+ "A Runtime.terminateExecution command overtakes earlier DontInterrupt evaluations "+ f"on the same {label} session, interrupts non-yielding JavaScript, then "+ "releases the queued evaluations in FIFO order with exactly-once responses."+ ),+ source=(+ "Chromium Worker DevTools IO-session executable probe; regression for Moli's "+ "former owner-only Worker Inspector queue"+ ),+ commands=[+ "Runtime.evaluate (non-yielding worker JavaScript)",+ "Runtime.evaluate x2 (DontInterrupt followers)",+ "Runtime.terminateExecution",+ "Runtime.evaluate (recovery)",+ ],+ observed={+ "targetId": worker_target_id,+ "responseOrder": response_order,+ },+ )++async def _debugger_io_catalog_during_active_javascript(client: RawCdpClient,page: InspectorRoutingPage,diff --git a/moli-cdp-smoke/moli_cdp_smoke/runner.py b/moli-cdp-smoke/moli_cdp_smoke/runner.pyindex eeb954950..22e6b48be 100644--- a/moli-cdp-smoke/moli_cdp_smoke/runner.py+++ b/moli-cdp-smoke/moli_cdp_smoke/runner.py@@ -81,7 +81,7 @@ class SmokeGroup:RAW_GROUPS: tuple[SmokeGroup, ...] = (SmokeGroup("inspector-routing",- "Chromium-calibrated active-JS IO interrupt, nested Main receiver, per-session FIFO, and non-V8 IO boundaries.",+ "Chromium-calibrated Page/Worker active-JS interrupt, nested Main receiver, per-session FIFO, and non-V8 IO boundaries.","raw",run_inspector_routing_group,),