WebView2 wpf control remote debugging port can't work

Spencer Hao Wang 21 Reputation points
2022-09-05T02:40:24.913+00:00

I'm using microsoft webview2 for my WPF app. As the document https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/webdriver says, I think I can use option "--remote-debugging-port=9222" to expose my content on webview2 control to web browser.

But when I open link "http://localhost:9222", this a blank page.

I would like to know whether webview2 support remote-debugging-port?

webview version:105.0.1343.25

Sample Code:
var env = await CoreWebView2Environment
.CreateAsync(options: new CoreWebView2EnvironmentOptions(
"--remote-debugging-port=9222"));
await webView.EnsureCoreWebView2Async(env);
webView.Source = new Uri( "https://www.microsoft.com");

Developer technologies | Windows Presentation Foundation
Developer technologies | Visual Studio | Debugging
Microsoft Edge | Microsoft Edge development
{count} votes

Accepted answer
  1. Anonymous
    2022-09-07T01:38:33.01+00:00

    Hi @Spencer Hao Wang ,

    Yes, WebView2 does support remote-debugging-port. But I'm afraid you cannot expose the content on webview2 control to web browser. After completing the tutorial, you will actually be able to automate your WebView2 project using Selenium and Edge Driver, as you can see by the end of the doc. In another word, remote debugging a WebView2 project allows your Edge Driver to take control of the project. For example, you can print the title of your current WebView2 content in the console if you add the following code after EdgeDriver e = new EdgeDriver(eo);:

    Console.Writeline(e.Title);  
    

    So, that's how remote debugging works. Of course, you can complete other driver tasks via some more advanced code.


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best Regards,
    Shijie Li


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.