MicrosoftEdge / WebView2Feedback

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

[Feature]: flat mode in CoreWebView2.CallDevToolsProtocolMethodAsync #4665

Closed trebahl closed 1 week ago

trebahl commented 3 weeks ago

Describe the feature/enhancement you need

DevTools has a so called flat mode where you specify a sessionId to apply commands to. I would like to specify a session id in CoreWebView2.CallDevToolsProtocolMethodAsync.

The scenario/use case where you would use this feature

I am using webview to display a pdf. I would like to programatically jump to a specific page, when certain events happen within my application. There is no visible api for that. However, using the inspector, I found that calling window.viewer.currentController_.goToPage should do the trick, provided I can inject javascript code into the context of the pdf viewer, which is hidden inside an embed, seemingly not accessible from the context of the main page.

If I call Target.getTargets I can find a target that seems to correspond to the insides of the embed. So I need to call Runtime.evaluate on the session id of this target.

How important is this request to you?

Critical. My app's basic functions wouldn't work without it.

Suggested implementation

According to https://github.com/aslushnikov/getting-started-with-cdp/blob/master/README.md, in order to use flat mode, you just need to add the session id as the first member in the toplevel object : await SEND(ws, { sessionId, id: 1, // Note that IDs are independent between sessions. method: 'Page.navigate', params: { url: 'https://pptr.dev', }, });

I suppose it wouldn't be difficult to have an overload of CallDevToolsProtocolMethodAsync accepting a session id argument.

What does your app do? Is there a pending deadline for this request?

My app is displaying a pdf manual, and jumping to the relevant part of it based on what the user is doing. So far I was using an older pdf viewer control (foxit), but I want to upgrade from .net framework to .net, and there does not appear to be a .net version of the foxit display library (it seems to be retired; they are now only selling libraries to read and write pdfs). I can't upgrade to .net until I find a replacement viewer.

trebahl commented 2 weeks ago

Sorry, I have just discovered that it is already possible with CoreWebView2.CallDevToolsProtocolMethodForSessionAsync.

victorhuangwq commented 1 week ago

Linking the API ref: https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2.calldevtoolsprotocolmethodforsessionasync?view=webview2-dotnet-1.0.1418.22