MicrosoftEdge / WebView2Feedback

Feedback and discussions about Microsoft Edge WebView2
https://aka.ms/webview2
441 stars 53 forks source link

Create a CoreWebView2Frame and add it to the FrameNavigationCompleted EventArgs #948

Closed darbid closed 2 years ago

darbid commented 3 years ago

I have a use case where I automate a single website. The main top document is loaded after login and the DOMContentLoaded event fires. This top document then rarely navigates again. It navigates if you logout or change the language for example.

The HTML changes via injections of HTML elements (AJAX) in same cases but also has a number of iFrames.

I see the comment here about CoreWebView2Frame has that progressed at all?

My feature request is that in the FrameNavigationCompleted that at least the Name, ID and URL could be identified. Even better would be that the event either passed a Frame object or the browser object.

In my use case and working with for example Chrome Extensions or CefSharp the various frame events seem to fire before the html of the iFrame is ready, therefore it would be great that there be some way to know when this iFrame's document is ready. I bring this up because you may consider adding a DOMContentLoaded event however I think this will cause a timing issue and may in same cases be set too late meaning it never fires. Ultimately a Status property or even event change would be really nice. This last part on document being ready of course is a "nice to have" as one could inject javascript into the Frame to check the status.

AB#31913810

champnic commented 3 years ago

@darbid Thanks for the feature request! We do have a Frame object concept on our backlog, and are investigating potential designs now. It's possible that the NavigationCompleted event for frames would be moved to the Frame object.

For your scenario, is the current issue that the FrameNavigationCompleted event doesn't give enough information for you to be able to identify the specific frame that's ready?

I'll add this as a scenario on our backlog. Thanks!

darbid commented 3 years ago

For your scenario, is the current issue that the FrameNavigationCompleted event doesn't give enough information for you to be able to identify the specific frame that's ready?

correct.

I have not tested this yet but it looks like AddScriptToExecuteOnDocumentCreatedAsync will inject into a new frame when it loads. If this does inject into all of the frames then I will use this. Chrome extensions provide a similar feature of js injection.

champnic commented 2 years ago

Hey @darbid - we now have a NavigationCompleted event on our CoreWebView2Frame object. Let me know if that doesn't look like it would solve your scenario here. Thanks! https://docs.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2frame.navigationcompleted?view=webview2-dotnet-1.0.1108.44

darbid commented 2 years ago

Thank you. I'll check it out.

sateeshmunagala commented 1 year ago

Is there any example of using the CoreWebView2Frame object in NavigationCompleted event. I could not find any examples over internet