Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support finding iframe elements by browsing context id #794

Open
OrKoN opened this issue Oct 5, 2024 · 1 comment
Open

Support finding iframe elements by browsing context id #794

OrKoN opened this issue Oct 5, 2024 · 1 comment
Labels
module-browsingContext Browsing Context module needs-discussion Issues to be discussed by the working group

Comments

@OrKoN
Copy link
Contributor

OrKoN commented Oct 5, 2024

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:

Implement DOM.getFrameOwner and DOM.describeNode to enable converting between DOM node handles and Frame handles. This would improve the implementation of Locator.contentFrame() and FrameLocator.owner(), as the current workaround using contentWindow does not work with shadow DOM, as seen in the page/frame-frame-element.spec.ts tests.

@OrKoN OrKoN added module-browsingContext Browsing Context module needs-discussion Issues to be discussed by the working group labels Oct 5, 2024
@christian-bromann
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module-browsingContext Browsing Context module needs-discussion Issues to be discussed by the working group
Projects
None yet
Development

No branches or pull requests

2 participants