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

Ability to retrieve iframe's BrowsingContext #418

Closed
Lightning00Blade opened this issue May 4, 2023 · 19 comments
Closed

Ability to retrieve iframe's BrowsingContext #418

Lightning00Blade opened this issue May 4, 2023 · 19 comments
Labels
needs-discussion Issues to be discussed by the working group remote value Serialization and Deserialization of Remote Values

Comments

@Lightning00Blade
Copy link
Contributor

Lightning00Blade commented May 4, 2023

When creating iframe an a Context (navigatable) is created, but there is no way get its id if you know the element, this is need for example if you need to execute a command on a specific iframe, or listen on it's events.
CDP exposes 2 ways of doing this.
During the navigation event (from about:blank to iframe.src) Page.frameNavigated, a property name that contains the iframe's name, id or null.
Using Handle and calling DOM.describeNode. Return has a frameId property.

@whimboo
Copy link
Contributor

whimboo commented May 4, 2023

The browsingContext.Info type has a context field, which is a string and matches the id of the BrowsingContext.

@OrKoN
Copy link
Contributor

OrKoN commented May 5, 2023

I believe the issue is that it is not possible to know from a serialized iframe element what context it currently belongs to.

@juliandescottes
Copy link
Contributor

So to summarize there's no issue with browsingContext.contextCreated, as you should get the context and parent fields for the new context which was created. The issue is that you want a way to link the serialized frame to the context which corresponds to its contentWindow?

@OrKoN
Copy link
Contributor

OrKoN commented May 5, 2023

That's right: basically the implementation for https://pptr.dev/api/puppeteer.elementhandle.contentframe/

@OrKoN
Copy link
Contributor

OrKoN commented May 5, 2023

@jgraham
Copy link
Member

jgraham commented May 5, 2023

So in theory one can nearly implement this in script like callFunction((iframe) => iframe.contentWindow, arguments=[frame]). But the reason it doesn't quite work is that WindowProxyRemoteValue doesn't contain the context id for the browsing context (really navigable) containing the window. So I wonder if it would be enough to just give WindowProxyRemoteValue a value field with a context property containing that id (we could use sharedId for this, but that ends up erasing the difference between a browsing context and a navigable; we really want context to mean "navigable" and the sharedId on a WindowProxy should really change when the underlying object changes).

@OrKoN
Copy link
Contributor

OrKoN commented May 5, 2023

Adding context to the serialisation result of evaluating contentWindow would be sufficient, I believe. cc @sadym-chromium would it be feasible from the implementation perspective (I think it is another instance of the layering violation from Chromium's perspective)?

@whimboo
Copy link
Contributor

whimboo commented May 5, 2023

I see. If we add such a value should we keep it in sync with the WindowProxy serialization in WebDriver classic? Probably yes.

@whimboo whimboo changed the title Ability to retrive iframe's BrowsingContext Ability to retrieve iframe's BrowsingContext May 16, 2023
@sadym-chromium
Copy link
Contributor

Adding context to the serialisation result of evaluating contentWindow would be sufficient, I believe. cc @sadym-chromium would it be feasible from the implementation perspective (I think it is another instance of the layering violation from Chromium's perspective)?

let me check it out

@sadym-chromium
Copy link
Contributor

Adding context to the serialisation result of evaluating contentWindow would be sufficient, I believe. cc @sadym-chromium would it be feasible from the implementation perspective (I think it is another instance of the layering violation from Chromium's perspective)?

As frameId is accessible from the DOM.describeNode, and accessible from the protocol inspector, I guess we can add the context value to the window.

@sadym-chromium
Copy link
Contributor

sadym-chromium commented Jun 14, 2023

Adding context to the serialisation result of evaluating contentWindow would be sufficient, I believe. cc @sadym-chromium would it be feasible from the implementation perspective (I think it is another instance of the layering violation from Chromium's perspective)?

demo of what it can look like: https://crrev.com/c/4613547

@jgraham
Copy link
Member

jgraham commented Jul 26, 2023

I think this was resolved by #452

@OrKoN
Copy link
Contributor

OrKoN commented Nov 30, 2023

@whimboo and I found that the contentWindow can be null for certain types (I guess cross-origin isolated?) of iframes in Firefox. I think we overlooked this aspect when discussing this issue and perhaps we need to revisit.

https://html.spec.whatwg.org/multipage/document-sequences.html#content-window

@OrKoN OrKoN reopened this Nov 30, 2023
@whimboo whimboo added remote value Serialization and Deserialization of Remote Values needs-discussion Issues to be discussed by the working group labels Nov 30, 2023
@whimboo
Copy link
Contributor

whimboo commented Nov 30, 2023

Specifically for Firefox you can see the restrictions in-place for cross-origin iframes here:
https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy#cross-origin_script_api_access

@jgraham
Copy link
Member

jgraham commented Nov 30, 2023

But that doesn't say that contentWindow should be null. Do we have a non-WebDriver testcase (i.e. just HTML and JS)
where we get different contentWindow values in Chrome and Firefox?

@OrKoN
Copy link
Contributor

OrKoN commented Nov 30, 2023

@jgraham for example https://mathiasbynens.github.io/css-dbg-stories/iframe-navigations.html (Click append iframe with a cross-origin URL). It returns null in Firefox.

@whimboo
Copy link
Contributor

whimboo commented Nov 30, 2023

@OrKoN are you sure? We are actually talking about the contentWindow and not contentDocument. The former one is present for me when I follow the steps from your last comment.

@OrKoN
Copy link
Contributor

OrKoN commented Nov 30, 2023

@whimboo you are totally right. I made a mistake in a hurry :( The contentWindow is not null but it seems to be being serialized as an "object" instead of a "window" in Firefox (thus, missing the context attribute).

@whimboo
Copy link
Contributor

whimboo commented Nov 30, 2023

After some investigation I found that this is actually a bug in our BiDi implementation in Firefox. I filed https://bugzilla.mozilla.org/show_bug.cgi?id=1867667 to get this fixed. There doesn't seem to be anything needed spec wise as of this point.

@whimboo whimboo closed this as not planned Won't fix, can't repro, duplicate, stale Nov 30, 2023
@whimboo whimboo closed this as completed Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-discussion Issues to be discussed by the working group remote value Serialization and Deserialization of Remote Values
Projects
None yet
Development

No branches or pull requests

6 participants