Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
refactor(cdp): simplify renderer call envelopes and unit replies
ldm004d465959f9e
diff --git a/moli-core/src/page/renderer_command_support.rs b/moli-core/src/page/renderer_command_support.rsindex 94203125d..0645e0c09 100644--- a/moli-core/src/page/renderer_command_support.rs+++ b/moli-core/src/page/renderer_command_support.rs@@ -1760,7 +1760,7 @@ impl Page {operation,);Ok((- self.start_page_command(RendererPageCommand::Native(Box::new(command)))?,+ self.start_page_command(RendererPageCommand::Native(command))?,guard,))}diff --git a/moli-protocol/src/domains/css/native.rs b/moli-protocol/src/domains/css/native.rsindex fe2f35dae..caf2e197f 100644--- a/moli-protocol/src/domains/css/native.rs+++ b/moli-protocol/src/domains/css/native.rs@@ -46,11 +46,7 @@ pub(crate) fn try_start(conn: &mut CdpConnection, cmd: &Cmd<'_>) -> Option<NativCommand::ResetCssAgentSession {inspector_session_id,},- |reply| match reply {- Ok(Reply::Unit) => Response::success(json!({})),- Err(error) => Response::error(-32000, error.to_string()),- _ => unreachable!("CSS reset reply"),- },+ native::unit_response,)}CssAction::GetStyleSheet => {diff --git a/moli-protocol/src/domains/dom_debugger/native.rs b/moli-protocol/src/domains/dom_debugger/native.rsindex 76ffb9a67..0f4c003cc 100644--- a/moli-protocol/src/domains/dom_debugger/native.rs+++ b/moli-protocol/src/domains/dom_debugger/native.rs@@ -106,7 +106,7 @@ fn prepare(breakpoint,enabled,},- unit,+ native::unit_response,))}DomDebuggerAction::SetXHRBreakpoint | DomDebuggerAction::RemoveXHRBreakpoint => {@@ -130,16 +130,8 @@ fn prepare(breakpoint,enabled,},- unit,+ native::unit_response,))}}}--fn unit(reply: anyhow::Result<Reply>) -> Response {- match reply {- Ok(Reply::Unit) => Response::success(json!({})),- Err(error) => Response::error(-32000, error.to_string()),- _ => unreachable!("DOMDebugger configuration reply"),- }-}diff --git a/moli-protocol/src/domains/emulation/native_configuration.rs b/moli-protocol/src/domains/emulation/native_configuration.rsindex d16cdaa19..a7344003c 100644--- a/moli-protocol/src/domains/emulation/native_configuration.rs+++ b/moli-protocol/src/domains/emulation/native_configuration.rs@@ -83,9 +83,5 @@ pub(super) fn try_start_surface(}pub(super) fn unit(command: Command) -> Operation {- Operation::new(command, |reply| match reply {- Ok(Reply::Unit) => Response::success(json!({})),- Err(error) => Response::error(-32000, error.to_string()),- _ => unreachable!("configuration acknowledgement"),- })+ Operation::new(command, native::unit_response)}diff --git a/moli-protocol/src/domains/native.rs b/moli-protocol/src/domains/native.rsindex acffd62f9..69539eeb2 100644--- a/moli-protocol/src/domains/native.rs+++ b/moli-protocol/src/domains/native.rs@@ -19,6 +19,16 @@ use crate::conn::{TargetPageResidenceIdentity,};+pub(crate) fn unit_response(+ reply: anyhow::Result<RendererPageReply>,+) -> RendererNativeProtocolResponse {+ match reply {+ Ok(RendererPageReply::Unit) => RendererNativeProtocolResponse::success(json!({})),+ Err(error) => RendererNativeProtocolResponse::error(-32000, error.to_string()),+ _ => unreachable!("native Unit command reply"),+ }+}+pub(crate) enum NativeCommandStep {Pending(PendingNativeCommand),Complete(CommandOutputPlan),diff --git a/moli-protocol/src/domains/page/native.rs b/moli-protocol/src/domains/page/native.rsindex c7f412a96..3810fbcf7 100644--- a/moli-protocol/src/domains/page/native.rs+++ b/moli-protocol/src/domains/page/native.rs@@ -159,11 +159,7 @@ fn prepare(.ok_or_else(|| CommandOutputPlan::error(-31998, "BrowserContextNotLoaded"))?;Ok(Operation::new(Command::SetBypassContentSecurityPolicy(enabled),- |reply| match reply {- Ok(Reply::Unit) => Response::success(json!({})),- Err(error) => Response::error(-32000, error.to_string()),- _ => unreachable!("Page CSP configuration reply"),- },+ native::unit_response,))}PageAction::ResetNavigationHistory => Ok(Operation::new(diff --git a/moli-renderer-v8/src/runtime/page_surface.rs b/moli-renderer-v8/src/runtime/page_surface.rsindex cd4a558d6..80d2bdb99 100644--- a/moli-renderer-v8/src/runtime/page_surface.rs+++ b/moli-renderer-v8/src/runtime/page_surface.rs@@ -4657,7 +4657,8 @@ pub(crate) enum RendererInspectorPageCommand {#[non_exhaustive]pub enum RendererPageCommand {- Native(Box<RendererCdpCall>),+ // The call fits inline; its operation boxes the recursively contained page command.+ Native(RendererCdpCall),Inspector(RendererInspectorCommandEnvelope),EvaluateExpression {expression: String,diff --git a/moli-renderer-v8/src/runtime/protocol_output/native_response.rs b/moli-renderer-v8/src/runtime/protocol_output/native_response.rsindex 4c715d90d..1f40a95e3 100644--- a/moli-renderer-v8/src/runtime/protocol_output/native_response.rs+++ b/moli-renderer-v8/src/runtime/protocol_output/native_response.rs@@ -233,6 +233,7 @@ impl RendererNativeCommandReadyResponse {/// inside the same renderer turn; only the terminal projection can publish a/// frontend response. These continuations never await Browser state or I/O.pub struct RendererNativeOperation {+ // Breaks the Native call -> operation -> page command type cycle.pub(crate) command: Box<RendererPageCommand>,completion: NativeOperationCompletion,nested_main: bool,diff --git a/moli-renderer-v8/src/runtime/tests/extracted/runtime_scripts.rs b/moli-renderer-v8/src/runtime/tests/extracted/runtime_scripts.rsindex aed128925..762341112 100644--- a/moli-renderer-v8/src/runtime/tests/extracted/runtime_scripts.rs+++ b/moli-renderer-v8/src/runtime/tests/extracted/runtime_scripts.rs@@ -2733,7 +2733,7 @@ async fn native_terminals_publish_before_waiters_are_polled() {pending.push((command_id,page.enqueue_protocol_command_in_inspector_session(- RendererPageCommand::Native(Box::new(command)),+ RendererPageCommand::Native(command),Some("session-a".to_owned()),).expect("enqueue native terminal"),@@ -2883,7 +2883,7 @@ async fn projected_native_success_and_error_publish_without_adapter_receipt() {guards.push(guard);waiters.push(page.enqueue_protocol_command_in_inspector_session(- RendererPageCommand::Native(Box::new(command)),+ RendererPageCommand::Native(command),Some("native".to_owned()),).unwrap(),