Bug 301932

Summary: [WebDriver][BiDi] Process incoming frame handles before calling WebAutomationSession
Product: WebKit Reporter: Lauro Moura <lmoura>
Component: WebDriverAssignee: Lauro Moura <lmoura>
Status: RESOLVED FIXED    
Severity: Normal CC: bburg, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   

Lauro Moura
Reported 2025-11-04 06:37:37 PST
While reviewing the browsing context handle PR at https://github.com/WebKit/WebKit/pull/53361, and while working on the "subscribe to specific user context" for bug282981, I saw that currently we're not translating the incoming context handles properly. There are some cases in bidi where we can get a command with a single frame handle (i.e. frame-<UUID> strings) as the context. For example, some tests issuing script.callFunction on specific child contexts, like `imported/w3c/webdriver/tests/bidi/session/subscribe/contexts.py::test_subscribe_to_child_context` Meanwhile, in Classic, the driver kept the state of the currently selected browsing context, usually sending the toplevel context + frame handle when needed. So, in order to BiDi agents properly resolve the handles before forwarding to the Classic code, where applicable, it should get the top level handle associated with the incoming frame handle. Otherwise, we risk raising `WindowNotFound` if we just pass the frame handle when doing `RefPtr webPageProxy = session->webPageProxyForHandle(browsingContext);`
Attachments
Lauro Moura
Comment 1 2025-11-05 05:35:38 PST
Here's an example that's currently raising `WindowNotFound` (using WPT's `webdriver` library to access the raw function). The expected behavior is that we can replace the text inside both the top level target and the target inside the frame. ``` async with session.bidi_session as bidi_session: contexts = await bidi_session.browsing_context.get_tree() top_context = contexts[0] child_frame = top_context["children"][0] js_code = """() => {{ let target = document.getElementById("target"); target.innerHTML = "{context}"; }} """ # Replace parent context text await bidi_session.script.call_function( function_declaration=js_code.format(context=top_context['context']), arguments=[], await_promise=False, target=ContextTarget(top_context['context'])) # Replace child frame text - RAISING WindowNotFound here await bidi_session.script.call_function( function_declaration=js_code.format(context=child_frame['context']), arguments=[], await_promise=False, target=ContextTarget(child_frame['context'])) ``` And demo page: ``` <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <iframe sandbox srcdoc=" <p id=&quot;target&quot;>Inside iframe</p> " ></iframe> <div id=target>Outer frame</div> </article> </body> </html> ``` Patch incoming.
Lauro Moura
Comment 2 2025-11-09 19:56:33 PST
Radar WebKit Bug Importer
Comment 3 2025-11-11 06:38:10 PST
EWS
Comment 4 2025-11-19 16:31:06 PST
Committed 303294@main (b65e8b5c0008): <https://commits.webkit.org/303294@main> Reviewed commits have been landed. Closing PR #53658 and removing active labels.
Note You need to log in before you can comment on or make changes to this bug.