Open OrKoN opened 1 month ago
This would be helpful for WebdriverIO as well as we currently have to maintain rather complicated mechanism to support automated piercing through shadow roots. If the user switches into an iframe
we loose the ability to use the same mechanism for element lookups as it doesn't seem trivial to keep track of the context id the user is in. Users still like to switch to iframes
by providing an element id to that element node. It would be helpful as well if Bidi could have an event for when user switch to different contexts. WebdriverIO could keep these changes in memory and use it for upcoming element look ups.
The Browser Testing and Tools Working Group just discussed Support finding iframe elements by browsing context id
.
jgraham: if we need to call getTree to be able to use the command that complicates this
Having only a sharedId
without browsing context it belongs to does not make that much sense, so the user needs it anyways.
Puppeteer offers a way to get the frame owner element using the browsing context/navigable ID via the
Frame.frameElement()
API. Currently, the implementation in Puppeteer relies on finding all iframe/frame elements, serializing their contentWindow and comparing the ID of the serialized window to the id of the target frame. That does not work for Shadow roots as it is not possible to locate iframe/frame elements within closed shadow roots.The following solutions are possible:
1) Add browsingContext.getFrameOwner(browsingContextId) -> sharedReference 2) Modify locateNodes to allow piercing shadow roots including DOM nodes 3) Extend locateNodes with a new locator type (e.g., FrameOwnerLocator)
Note that having a dedicated locator or method would allow for a more efficient implementation as generally implementations do not need to look over the entire dom tree to find a frame owner element for a given navigable. In the HTML spec terms this seems to correspond to the concept of a navigable container: https://html.spec.whatwg.org/multipage/document-sequences.html#navigable-container
Related Playwright feedback: