Skip to content

Commit bdf7356

Browse files
committed
Fix WebView2 debugging with VS Code
1 parent 78bbf1b commit bdf7356

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

microsoft-edge/webview2/how-to/debug-visual-studio-code.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ The following code demonstrates launching the app from Visual Studio Code (rathe
2828
"request": "launch",
2929
"runtimeExecutable": "C:/path/to/your/webview2/app.exe",
3030
"env": {
31+
// The following variable is needed when "runtimeExecutable" property is set.
32+
// The port number below shall match the value of "port" property above.
33+
"WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS": "--remote-debugging-port=9222"
3134
// Customize for your app location if needed.
3235
"Path": "%path%;e:/path/to/your/app/location; "
3336
},
@@ -38,6 +41,7 @@ The following code demonstrates launching the app from Visual Studio Code (rathe
3841
"webRoot": "${workspaceFolder}/path/to/your/assets"
3942
```
4043

44+
> Instead of setting the `WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS` environment variable, you can add a new registry value named `<myApp.exe>` with data `--remote-debugging-port=9222` to the registry under registry key `Computer\HKEY_CURRENT_USER\Software\Policies\Microsoft\Edge\WebView2\AdditionalBrowserArguments`, so that the debugger can find the proper port. See [WewbView2 browser flags](../concepts/webview-features-flags.md) for more information.
4145
4246
<!-- ---------------------------------- -->
4347
#### Command-line URL parameter passed in
@@ -109,8 +113,7 @@ You might need to attach the debugger to running WebView2 processes. To do that
109113
"runtimeExecutable": "C:/path/to/your/webview2/myApp.exe",
110114
"env": {
111115
"Path": "%path%;e:/path/to/your/build/location; "
112-
},
113-
"useWebView": true
116+
}
114117
```
115118

116119
Your WebView2 control must open the Chrome Developer Protocol (CDP) port to allow debugging of the WebView2 control. Your code must be built to ensure that only one WebView2 control has a CDP port open, before starting the debugger.
@@ -143,6 +146,7 @@ You also need to add a new REGKEY `<myApp.exe> = --remote-debugging-port=9222` u
143146

144147
![The resulting registry key in the Registry Editor](./debug-visual-studio-code-images/set-debugging-port-registry-key.png)
145148

149+
> Instead of adding the above registry key, you can set the `WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS` environment variable to `--remote-debugging-port=9222`. Make sure that your application was started after the environment variable had been set, and that your application inherits the variable. See [WewbView2 browser flags](../concepts/webview-features-flags.md) for more information.
146150
147151
<!-- ====================================================================== -->
148152
## Debug tracing options

0 commit comments

Comments
 (0)