Skip to content

armgit / moli

Public Imported from GitHub
0

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

refactor(cdp): remove single-variant DOM and AX work wrappers

ldm07cef1b4e516c
diff --git a/moli-protocol/src/domains/accessibility.rs b/moli-protocol/src/domains/accessibility.rs
index a3d9680c9..276143979 100644
--- a/moli-protocol/src/domains/accessibility.rs
+++ b/moli-protocol/src/domains/accessibility.rs
@@ -16,14 +16,14 @@ pub(crate) struct PendingAccessibilityCommandDispatch {
command_id: Option<u64>,
owner_scope: CommandOwnerScope,
kind: PendingAccessibilityCommandKind,
- pending: PendingAccessibilityCommandWork,
+ pending: PendingPageCommand,
}
pub(crate) struct CompletedAccessibilityCommandDispatch {
command_id: Option<u64>,
owner_scope: CommandOwnerScope,
kind: PendingAccessibilityCommandKind,
- completed: CompletedAccessibilityCommandWork,
+ completed: Box<Result<CompletedPageCommand, String>>,
}
pub(crate) enum AccessibilityCommandDispatchStep {
@@ -57,14 +57,6 @@ enum PendingAccessibilityCommandKind {
},
}
-enum PendingAccessibilityCommandWork {
- Page(PendingPageCommand),
-}
-
-enum CompletedAccessibilityCommandWork {
- Page(Box<Result<CompletedPageCommand, String>>),
-}
-
#[derive(Clone)]
enum AccessibilityNodeOperation {
Children,
@@ -88,7 +80,7 @@ impl PendingAccessibilityCommandDispatch {
conn: &CdpConnection,
cmd: &Cmd<'_>,
kind: PendingAccessibilityCommandKind,
- pending: PendingAccessibilityCommandWork,
+ pending: PendingPageCommand,
) -> Self {
Self {
command_id: cmd.id,
@@ -99,13 +91,7 @@ impl PendingAccessibilityCommandDispatch {
}
pub async fn wait(self) -> CompletedAccessibilityCommandDispatch {
- let completed = match self.pending {
- PendingAccessibilityCommandWork::Page(pending) => {
- CompletedAccessibilityCommandWork::Page(Box::new(
- pending.wait().await.map_err(|error| error.to_string()),
- ))
- }
- };
+ let completed = Box::new(self.pending.wait().await.map_err(|error| error.to_string()));
CompletedAccessibilityCommandDispatch {
command_id: self.command_id,
owner_scope: self.owner_scope,
@@ -457,7 +443,7 @@ fn start_pending_object_reference_command(
top_frame_id,
operation,
},
- PendingAccessibilityCommandWork::Page(pending),
+ pending,
)))
}
@@ -501,7 +487,7 @@ fn start_pending_dom_node_reference_command(
top_frame_id,
operation,
},
- PendingAccessibilityCommandWork::Page(pending),
+ pending,
)))
}
@@ -565,7 +551,7 @@ fn start_pending_backend_reference_command(
top_frame_id,
operation,
},
- PendingAccessibilityCommandWork::Page(pending),
+ pending,
)))
}
@@ -644,10 +630,7 @@ fn start_pending_frame_scoped_accessibility_command(
(child_frame_kind, pending)
};
Ok(Some(PendingAccessibilityCommandDispatch::from_command(
- conn,
- cmd,
- kind,
- PendingAccessibilityCommandWork::Page(pending),
+ conn, cmd, kind, pending,
)))
}
@@ -677,7 +660,6 @@ pub(crate) async fn complete_pending_accessibility_command(
kind,
completed,
} = completed;
- let CompletedAccessibilityCommandWork::Page(completed) = completed;
let completed = *completed;
if let Err(message) = conn.ensure_document_accessible_for_owner(&owner_scope) {
@@ -805,7 +787,7 @@ pub(crate) async fn complete_pending_accessibility_command(
top_frame_id,
operation,
},
- pending: PendingAccessibilityCommandWork::Page(pending),
+ pending,
},
);
}
diff --git a/moli-protocol/src/domains/dom/resolve.rs b/moli-protocol/src/domains/dom/resolve.rs
index 1b2fe4320..9786489d4 100644
--- a/moli-protocol/src/domains/dom/resolve.rs
+++ b/moli-protocol/src/domains/dom/resolve.rs
@@ -130,14 +130,14 @@ pub(crate) struct PendingDomCommandDispatch {
pub(super) command_id: Option<u64>,
pub(super) owner_scope: CommandOwnerScope,
pub(super) kind: PendingDomCommandKind,
- pub(super) pending: PendingDomCommandWork,
+ pub(super) pending: PendingPageCommand,
}
pub(crate) struct CompletedDomCommandDispatch {
command_id: Option<u64>,
owner_scope: CommandOwnerScope,
kind: PendingDomCommandKind,
- completed: Result<CompletedDomCommandWork, String>,
+ completed: Result<Box<CompletedPageCommand>, String>,
}
impl CompletedDomCommandDispatch {
@@ -151,9 +151,7 @@ impl CompletedDomCommandDispatch {
pub(crate) fn renderer_output_predecessor(&self) -> Option<moli_core::RendererOutputFence> {
match &self.completed {
- Ok(CompletedDomCommandWork::Page(completion)) => {
- completion.renderer_output_predecessor()
- }
+ Ok(completion) => completion.renderer_output_predecessor(),
Err(_) => None,
}
}
@@ -352,18 +350,10 @@ pub(super) fn start_disable_dom_agent_command(
command_id: cmd.id,
owner_scope: owner,
kind: PendingDomCommandKind::DiscardDomAgentFrontendBindings,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
-pub(super) enum PendingDomCommandWork {
- Page(PendingPageCommand),
-}
-
-enum CompletedDomCommandWork {
- Page(Box<CompletedPageCommand>),
-}
-
#[derive(Clone)]
pub(super) enum PendingDomObjectReferenceOperation {
RequestNode,
@@ -412,12 +402,10 @@ pub(super) enum PendingSetChildNodesAfter {
impl PendingDomCommandDispatch {
pub(crate) async fn wait(self) -> CompletedDomCommandDispatch {
- let completed = match self.pending {
- PendingDomCommandWork::Page(pending) => Box::pin(pending.wait())
- .await
- .map(|completed| CompletedDomCommandWork::Page(Box::new(completed)))
- .map_err(|error| error.to_string()),
- };
+ let completed = Box::pin(self.pending.wait())
+ .await
+ .map(Box::new)
+ .map_err(|error| error.to_string());
CompletedDomCommandDispatch {
command_id: self.command_id,
owner_scope: self.owner_scope,
diff --git a/moli-protocol/src/domains/dom/resolve/command_start.rs b/moli-protocol/src/domains/dom/resolve/command_start.rs
index 715a7bc4d..f560c3985 100644
--- a/moli-protocol/src/domains/dom/resolve/command_start.rs
+++ b/moli-protocol/src/domains/dom/resolve/command_start.rs
@@ -388,7 +388,7 @@ pub(super) fn start_cdp_dom_focus_command(
kind: PendingDomCommandKind::Focus {
missing_node_message: "No node found for given backend id",
},
- pending: PendingDomCommandWork::Page(pending),
+ pending,
})
}
@@ -473,7 +473,7 @@ pub(super) fn start_cdp_dom_edit_command(
command_id: cmd.id,
owner_scope: owner,
kind: PendingDomCommandKind::EditDocumentNode,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
})
}
@@ -552,7 +552,7 @@ pub(super) fn start_devtools_remove_node_command(
command_id,
owner_scope: owner.clone(),
kind: PendingDomCommandKind::RemoveNode,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
@@ -607,7 +607,7 @@ pub(super) fn start_devtools_dom_geometry_command(
command_id,
owner_scope: owner.clone(),
kind,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
@@ -682,7 +682,7 @@ pub(super) fn start_devtools_describe_node_command(
cached_object_node: None,
top_frame_id,
},
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
@@ -764,7 +764,7 @@ pub(super) fn start_devtools_request_child_nodes_command(
command_id,
owner_scope: owner.clone(),
kind,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
}
@@ -881,7 +881,7 @@ pub(super) fn start_devtools_query_selector_command(
kind: PendingDomCommandKind::QuerySelectorLive {
multiple: command.multiple,
},
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}));
};
@@ -927,7 +927,7 @@ pub(super) fn start_devtools_query_selector_command(
kind: PendingDomCommandKind::QuerySelectorLive {
multiple: command.multiple,
},
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
}
@@ -1110,7 +1110,7 @@ pub(super) fn start_devtools_get_document_command(
operation,
top_frame_id,
},
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
@@ -1153,7 +1153,7 @@ pub(super) fn start_devtools_get_frame_owner_command(
command_id,
owner_scope: owner.clone(),
kind: PendingDomCommandKind::GetFrameOwner { frame_id },
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
@@ -1214,7 +1214,7 @@ pub(super) fn start_devtools_get_node_for_location_command(
command_id,
owner_scope: owner.clone(),
kind: PendingDomCommandKind::GetNodeForLocation { top_frame_id },
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
@@ -1316,7 +1316,7 @@ pub(super) fn start_devtools_resolve_node_command(
object_group: command.object_group,
top_frame_id,
},
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}));
}
let object_group = command.object_group;
@@ -1336,7 +1336,7 @@ pub(super) fn start_devtools_resolve_node_command(
object_group,
cache_top_frame_id: resolution.cache_top_frame_id,
},
- pending: PendingDomCommandWork::Page(resolution.pending),
+ pending: resolution.pending,
}))
}
@@ -1474,7 +1474,7 @@ pub(super) fn start_dom_object_reference_operation(
command_id,
owner_scope: owner.clone(),
kind: PendingDomCommandKind::RequestNodeObjectReference,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
PendingDomObjectReferenceOperation::Focus => {
@@ -1487,7 +1487,7 @@ pub(super) fn start_dom_object_reference_operation(
kind: PendingDomCommandKind::Focus {
missing_node_message: "Could not find node with given id",
},
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
PendingDomObjectReferenceOperation::GetOuterHtml { include_shadow_dom } => {
@@ -1502,7 +1502,7 @@ pub(super) fn start_dom_object_reference_operation(
command_id,
owner_scope: owner.clone(),
kind: PendingDomCommandKind::GetOuterHtmlObjectReference,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
PendingDomObjectReferenceOperation::DescribeNode {
@@ -1527,7 +1527,7 @@ pub(super) fn start_dom_object_reference_operation(
cached_object_node,
top_frame_id,
},
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
PendingDomObjectReferenceOperation::GetBoxModel
@@ -1542,7 +1542,7 @@ pub(super) fn start_dom_object_reference_operation(
command_id,
owner_scope: owner.clone(),
kind: PendingDomCommandKind::ObjectReferenceLiveClientRect { operation },
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
PendingDomObjectReferenceOperation::ScrollIntoViewIfNeeded { rect } => {
@@ -1557,7 +1557,7 @@ pub(super) fn start_dom_object_reference_operation(
command_id,
owner_scope: owner.clone(),
kind: PendingDomCommandKind::ScrollIntoViewIfNeededObjectReference,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
}
@@ -1591,7 +1591,7 @@ pub(super) fn start_devtools_push_nodes_by_backend_ids_command(
node_ids,
renderer_backend_positions,
},
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
@@ -1612,7 +1612,7 @@ pub(super) fn start_devtools_get_outer_html_command(
command_id,
owner_scope: owner.clone(),
kind: PendingDomCommandKind::GetOuterHtmlDocument,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}));
};
if let DevToolsDomNodeReference::FrontendNodeId(frontend_node_id) = reference {
@@ -1634,6 +1634,6 @@ pub(super) fn start_devtools_get_outer_html_command(
command_id,
owner_scope: owner.clone(),
kind,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
diff --git a/moli-protocol/src/domains/dom/resolve/node_completion.rs b/moli-protocol/src/domains/dom/resolve/node_completion.rs
index 28dc680ab..903b40b8e 100644
--- a/moli-protocol/src/domains/dom/resolve/node_completion.rs
+++ b/moli-protocol/src/domains/dom/resolve/node_completion.rs
@@ -35,8 +35,7 @@ pub(super) fn complete_pending_dom_command_result(
)));
}
};
- let CompletedDomCommandWork::Page(completion) = completed_work;
- let completion = *completion;
+ let completion = *completed_work;
let result = match completed.kind {
PendingDomCommandKind::ResolveFrontendNodeForGetAttributes { frontend_node_id } => {
@@ -389,7 +388,7 @@ pub(super) fn complete_pending_dom_command_result(
cache_object_id,
top_frame_id,
},
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
Err(error) => devtools_dom_command_task_complete(Err(DevToolsError::new(
@@ -835,7 +834,7 @@ where
command_id,
owner_scope: owner.clone(),
kind,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
})),
Err(error) => {
out.push_error(error.code, error.message);
@@ -874,7 +873,7 @@ where
command_id,
owner_scope: owner.clone(),
kind,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
Err(error) => devtools_dom_command_task_complete(Err(DevToolsError::new(
@@ -1646,7 +1645,7 @@ pub(super) fn complete_resolve_node_execution_context_frame_result(
object_group,
cache_top_frame_id: None,
},
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
Err(error) => devtools_dom_command_task_complete(Err(DevToolsError::new(
@@ -1673,7 +1672,7 @@ pub(super) fn complete_resolve_node_execution_context_frame_result(
object_group,
cache_top_frame_id: resolution.cache_top_frame_id,
},
- pending: PendingDomCommandWork::Page(resolution.pending),
+ pending: resolution.pending,
}))
}
Err(error) => devtools_dom_command_task_complete(Err(DevToolsError::from(error))),
diff --git a/moli-protocol/src/domains/dom/resolve/pending_command.rs b/moli-protocol/src/domains/dom/resolve/pending_command.rs
index 517c9a1b2..6f74fcea7 100644
--- a/moli-protocol/src/domains/dom/resolve/pending_command.rs
+++ b/moli-protocol/src/domains/dom/resolve/pending_command.rs
@@ -15,8 +15,7 @@ pub(super) fn complete_pending_dom_command(
return DomCommandTaskStep::Complete;
}
};
- let CompletedDomCommandWork::Page(completion) = completed_work;
- let completion = *completion;
+ let completion = *completed_work;
let renderer_inspector_session_id =
conn.target_renderer_runtime_inspector_session_id_for_owner(&owner_scope);
let include_whitespace = dom_agent_includes_whitespace_for_owner(conn, &owner_scope);
@@ -548,7 +547,7 @@ pub(super) fn complete_pending_dom_command(
cache_object_id,
top_frame_id,
},
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
Err(error) => {
@@ -620,7 +619,7 @@ pub(super) fn complete_pending_dom_command(
object_group,
cache_top_frame_id: None,
},
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
Err(error) => {
@@ -651,7 +650,7 @@ pub(super) fn complete_pending_dom_command(
object_group,
cache_top_frame_id: resolution.cache_top_frame_id,
},
- pending: PendingDomCommandWork::Page(resolution.pending),
+ pending: resolution.pending,
}))
}
Err(error) => {
diff --git a/moli-protocol/src/domains/dom/resolve/protocol_dispatch.rs b/moli-protocol/src/domains/dom/resolve/protocol_dispatch.rs
index 9d4629601..12ebe4d88 100644
--- a/moli-protocol/src/domains/dom/resolve/protocol_dispatch.rs
+++ b/moli-protocol/src/domains/dom/resolve/protocol_dispatch.rs
@@ -44,7 +44,7 @@ pub(super) fn start_devtools_get_attributes_command(
command_id,
owner_scope: owner.clone(),
kind: PendingDomCommandKind::GetAttributesLive,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
@@ -75,7 +75,7 @@ pub(super) fn start_document_frontend_node_binding_command(
command_id,
owner_scope: owner.clone(),
kind,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
@@ -102,7 +102,7 @@ pub(super) fn start_devtools_get_text_command(
command_id,
owner_scope: owner.clone(),
kind: PendingDomCommandKind::GetTextLive,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
@@ -132,7 +132,7 @@ pub(super) fn start_devtools_get_property_command(
command_id,
owner_scope: owner.clone(),
kind: PendingDomCommandKind::GetPropertyLive,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
@@ -575,6 +575,6 @@ pub(super) fn start_devtools_scroll_into_view_if_needed_command(
command_id,
owner_scope: owner.clone(),
kind,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
diff --git a/moli-protocol/src/domains/dom/search.rs b/moli-protocol/src/domains/dom/search.rs
index dab5800e1..8051f17d7 100644
--- a/moli-protocol/src/domains/dom/search.rs
+++ b/moli-protocol/src/domains/dom/search.rs
@@ -5,7 +5,7 @@ use serde_json::json;
use super::resolve::{
DomCommandOutput, DomCommandTaskStep, PendingDomCommandDispatch, PendingDomCommandKind,
- PendingDomCommandStartError, PendingDomCommandWork,
+ PendingDomCommandStartError,
};
use super::*;
use crate::devtools_runtime::{
@@ -102,7 +102,7 @@ pub(super) fn start_devtools_perform_search_command(
command_id,
owner_scope: owner.clone(),
kind: PendingDomCommandKind::PerformSearchLive,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
@@ -129,7 +129,7 @@ pub(super) fn start_devtools_get_search_results_command(
command_id,
owner_scope: owner.clone(),
kind: PendingDomCommandKind::GetSearchResultsLive,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
@@ -151,7 +151,7 @@ pub(super) fn start_devtools_discard_search_results_command(
command_id,
owner_scope: owner.clone(),
kind: PendingDomCommandKind::DiscardSearchResultsLive,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
diff --git a/moli-protocol/src/domains/dom/set_file_input.rs b/moli-protocol/src/domains/dom/set_file_input.rs
index fb1f31fb3..1a66ef5d1 100644
--- a/moli-protocol/src/domains/dom/set_file_input.rs
+++ b/moli-protocol/src/domains/dom/set_file_input.rs
@@ -10,9 +10,8 @@ use super::loaded_page_mut_for_owner;
use super::node_references::{NodeReferenceParams, devtools_node_reference_from_ids};
use super::resolve::{
DevToolsDomCommandTaskStep, DomCommandOutput, DomCommandTaskStep, PendingDomCommandDispatch,
- PendingDomCommandKind, PendingDomCommandStartError, PendingDomCommandWork,
- devtools_dom_command_task_complete, dom_object_reference_id_for_owner,
- start_document_node_snapshot_for_reference,
+ PendingDomCommandKind, PendingDomCommandStartError, devtools_dom_command_task_complete,
+ dom_object_reference_id_for_owner, start_document_node_snapshot_for_reference,
};
use crate::conn::{CdpConnection, Cmd, CommandOwnerScope};
use crate::devtools_runtime::{
@@ -119,7 +118,7 @@ pub(super) fn start_devtools_set_file_input_files_command(
files: command.files,
append: command.append,
},
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}));
}
start_set_file_input_files_for_remote_reference(
@@ -436,7 +435,7 @@ fn start_set_file_input_files_frontend_node_binding(
file_paths,
append,
},
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
@@ -485,7 +484,7 @@ fn start_set_file_input_files_preflight_dispatch(
file_paths,
append,
},
- pending: PendingDomCommandWork::Page(pending),
+ pending,
})
}
@@ -502,7 +501,7 @@ fn start_set_file_input_files_for_reference_dispatch(
command_id,
owner_scope: owner.clone(),
kind: PendingDomCommandKind::SetFileInputFiles,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
})
}
@@ -543,7 +542,7 @@ fn start_set_file_input_files_for_runtime_object(
command_id,
owner_scope: owner.clone(),
kind: PendingDomCommandKind::SetFileInputFilesObjectReference,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
})
}
diff --git a/moli-protocol/src/domains/dom/stack_traces.rs b/moli-protocol/src/domains/dom/stack_traces.rs
index 989ac3e70..5ef6dcba6 100644
--- a/moli-protocol/src/domains/dom/stack_traces.rs
+++ b/moli-protocol/src/domains/dom/stack_traces.rs
@@ -4,7 +4,7 @@ use serde_json::json;
use super::resolve::{
DomCommandOutput, DomCommandTaskStep, PendingDomCommandDispatch, PendingDomCommandKind,
- PendingDomCommandStartError, PendingDomCommandWork,
+ PendingDomCommandStartError,
};
use super::*;
@@ -39,7 +39,7 @@ pub(super) fn start_set_node_stack_traces_enabled_command(
command_id: cmd.id,
owner_scope: owner,
kind: PendingDomCommandKind::SetNodeStackTracesEnabled,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}
@@ -63,7 +63,7 @@ pub(super) fn start_get_node_stack_traces_command(
command_id: cmd.id,
owner_scope: owner,
kind: PendingDomCommandKind::GetNodeStackTraces,
- pending: PendingDomCommandWork::Page(pending),
+ pending,
}))
}