[webdriver] Implement get shadow root (#37280)

Implement Get Element Shadow Root
https://www.w3.org/TR/webdriver2/#dfn-get-element-shadow-root

cc: @xiaochengh, @yezhizhen, @PotatoCP 

Testing:
`\tests\wpt\tests\webdriver\tests\classic\get_element_shadow_root\get.py`
is blocked by `no_browsing_context` and `closed_window`
pass for other sub-tests.

Signed-off-by: batu_hoang <longvatrong111@gmail.com>
This commit is contained in:
batu_hoang 2025-06-08 04:54:36 +08:00 committed by GitHub
parent c808ff7666
commit aeca81c091
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 53 additions and 0 deletions

View file

@ -2280,6 +2280,14 @@ impl ScriptThread {
can_gc,
)
},
WebDriverScriptCommand::GetElementShadowRoot(element_id, reply) => {
webdriver_handlers::handle_get_element_shadow_root(
&documents,
pipeline_id,
element_id,
reply,
)
},
WebDriverScriptCommand::ElementClick(element_id, reply) => {
webdriver_handlers::handle_element_click(
&documents,

View file

@ -843,6 +843,27 @@ pub(crate) fn handle_find_element_elements_tag_name(
.unwrap();
}
/// <https://www.w3.org/TR/webdriver2/#dfn-get-element-shadow-root>
pub(crate) fn handle_get_element_shadow_root(
documents: &DocumentCollection,
pipeline: PipelineId,
element_id: String,
reply: IpcSender<Result<Option<String>, ErrorStatus>>,
) {
reply
.send(
find_node_by_unique_id(documents, pipeline, element_id).and_then(|node| match node
.downcast::<Element>(
) {
Some(element) => Ok(element
.GetShadowRoot()
.map(|x| x.upcast::<Node>().unique_id(pipeline))),
None => Err(ErrorStatus::NoSuchElement),
}),
)
.unwrap();
}
pub(crate) fn handle_will_send_keys(
documents: &DocumentCollection,
pipeline: PipelineId,