WebView2Feedback icon indicating copy to clipboard operation
WebView2Feedback copied to clipboard

FrameCreated is not called for iframe inside another iframe

Open q71114 opened this issue 3 years ago • 22 comments

Description FrameCreated is not called for iframe inside another iframe.

Version SDK: 1.0.1222-prerelease Runtime: Evergreen, 101.0.1210.39 Framework: WPF OS: Win11

Repro Steps

  1. Added event handler to CoreWebView2.FrameCreated.
  2. Open a website with nested iframes, for example this one.

Expectation: CoreWebView2.FrameCreated is raised for both iframes. Actual: Only one CoreWebView2.FrameCreated is raised (which is for the top level iframe).

AB#40114362

q71114 avatar May 10 '22 13:05 q71114

Thanks for the bug report @q71114, and sorry you are running into this. I've added this to our backlog to take a look. @vbryh-msft FYI.

champnic avatar May 10 '22 22:05 champnic

Hi @q71114 FrameCreated event is raised currently only for top level iframes - this is known limitation. Could you please describe your scenario - why do you need nested iframes also and how are you going to use them. Thanks!

vbryh-msft avatar May 10 '22 22:05 vbryh-msft

Hi @vbryh-msft, we need to be able to send / receive message from all iframes in order to monitor / pause / resume camera and microphone usage as currently this is the only way to do it. If this limitation with iframes could not be removed having this feature request implemented would be the next best thing if it can be extended with pausing / resuming the permission in use as well.

q71114 avatar May 11 '22 08:05 q71114

@q71114 are your nested iframes in the same origin as top level iframes/parent page - or they all can be different?

vbryh-msft avatar May 11 '22 15:05 vbryh-msft

@vbryh-msft We need this to work with any setup so they can all be different.

q71114 avatar May 11 '22 16:05 q71114

Closed by mistake.

q71114 avatar May 23 '22 13:05 q71114

I would also like to a request for this feature.

We have an application using WebView2. Our users put enter a URL that they are in control of and we need to be able to read the contents of the webpage. One of our users has a webpage containing an iframe inside an iframe and we are unable to see it.

We would like to be able to work with nested frames the same way we work with top level frames. A nested frame could either trigger the CoreWebView2.FrameCreated or it could trigger a new CoreWebView2Frame.FrameCreated created.

Thank you

perelmanari avatar Feb 17 '23 19:02 perelmanari

Please fix this issue ASAP.

Kay-Burchardt avatar Apr 06 '23 15:04 Kay-Burchardt

Can we get an update on this? Is this something that you are planning on addressing? Is there any timeline?

Thank you

perelmanari avatar Jun 05 '23 14:06 perelmanari

@perelmanari - sorry, there is no work currently in progress for this feature. Do you think we can come up with some workaround on JS side? I was thinking if you can use AddScriptToExecuteOnDocumentCreated which should work for nested and then use JS postMessage ?

vbryh-msft avatar Jun 05 '23 16:06 vbryh-msft

Unfortunately, I don't think there is a workaround using Javascript. If a nested frame is cross-domain, then javascript wouldn't have access to it at all and interacting with cross-domain nested frames is exactly what I need to do.

perelmanari avatar Jun 05 '23 18:06 perelmanari

Second linked doc says: The window.postMessage() method safely enables cross-origin communication - have you given it a try?

vbryh-msft avatar Jun 05 '23 18:06 vbryh-msft

It would take a lot of javascript code and experimenting, but it seems like I could use a combination of those two to get a lot of functionality. I could detect document created and use that to know there is a new frame (FrameCreated) or an existing frame has navigated. Javascript could give me ReadyStateChanged events. I could use postMessage both directions to get similar functionality to ExecuteScriptAsync. Do you have any thoughts on how this could work to get NavigationStarting and WebResourceRequested events?

perelmanari avatar Jun 05 '23 19:06 perelmanari

I have been experimenting using the devtools protocol to get events (Page.frameAttached, Page.frameDetached, Page.lifecycleEvent, Network.requestWillBeSent, Network.responseReceived, etc). Overall, this has been working well to achieve what I need. However, I am unable to get any events to fire on cross site frames.

This chromium bug report has information: https://bugs.chromium.org/p/chromium/issues/detail?id=924937#c13

I am able to use Target.setAutoAttached and get the Target.attachedToTarget event with the sessionId for the iframe. However, CoreWebView2.CallDevToolsProtocolMethodAsync does not have any way to pass a sessionId. It only allows for methodName and parametersAsJson.

Is there any way to do this currently with WebView2? Should I add a separate feature request to add an overload for CallDevToolsProtocolMethodAsync that accepts a sessionId?

perelmanari avatar Jul 11 '23 21:07 perelmanari

Thank you for trying. We have method with sessionId input parameter - CallDevToolsProtocolMethodForSessionAsync

vbryh-msft avatar Jul 11 '23 21:07 vbryh-msft

I can't believe I completely missed that method. Thank you.

perelmanari avatar Jul 11 '23 21:07 perelmanari

Using that method, I am now able to see events from the cross site frames. I miss a few events due to async timing, but I can work around that. I think I will be able to get all the functionality I need this way.

Thank you for your help.

perelmanari avatar Jul 11 '23 23:07 perelmanari

Hello, we are looking into this feature request and I have a follow up question: @q71114 do you know the hierarchy of the nested iframes? Thanks!

nishitha-burman avatar Oct 17 '23 18:10 nishitha-burman

Hi @nishitha-burman,

Not sure I understood the question, but I used this example for testing so you can check out the hierarchy as needed.

q71114 avatar Oct 18 '23 08:10 q71114

Hi! Are there any news about this issue?

ynborokh avatar Nov 28 '23 17:11 ynborokh

Hello, we are looking into this feature request and I have a follow up question: @q71114 do you know the hierarchy of the nested iframes? Thanks!

We're building a browser, so need to support whatever hierarchy website creators implement (i.e. we have no idea what hierarchy to expect).

MarkIngramUK avatar Jan 10 '24 10:01 MarkIngramUK

Even if FrameNavigationStarting / FrameNavigationCompleted fire for all frames, it would be useful to fix this for the following reason:

FrameCreated is the only way to attach e.Frame.NavigationStarted / e.Frame.NavigationEnded, which are unique in that they receive CoreWebView2Frame as the sender. This lets you know the FrameId associated with with the navigation, which is helpful to keep track of which frames are doing which navigations.

(Of course, that use case could also be helped by providing FrameId on CoreWebView2NavigationStartingEventArgs / CoreWebView2NavigationCompletedEventArgs.)

wnayes avatar Jun 22 '24 14:06 wnayes

we need this as well

qkevin avatar Aug 09 '24 03:08 qkevin

A new API that allows developers to subscribe to the nested iframe creation event, giving them access to all properties, methods, and events of CoreWebView2Frame for the nested iframe is currently in the works.

The API is currently in review here: https://github.com/MicrosoftEdge/WebView2Feedback/pull/4982

victorhuangwq avatar Dec 13 '24 23:12 victorhuangwq

Hi all!

The FrameCreated API is now available as an experimental API in 1.0.3079-prerelease. Using this API, your app can subscribe to the nested iframe creation event, giving the app access to all properties, methods, and events of CoreWebView2Frame for the nested iframe.

Please give it a try and let us know if you have any feedback!

victorhuangwq avatar Jan 24 '25 18:01 victorhuangwq

cc// @MarkIngramUK @q71114 @pushkin-

victorhuangwq avatar Jan 24 '25 18:01 victorhuangwq