Skip to content

Commit eeb351d

Browse files
Merge pull request #3414 from mikosg/webview2_vscode_debug_2
Fix WebView2 debugging with VS Code
2 parents 78bbf1b + 4f0352d commit eeb351d

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

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

+18-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ms.author: msedgedevrel
66
ms.topic: conceptual
77
ms.service: microsoft-edge
88
ms.subservice: webview
9-
ms.date: 02/21/2025
9+
ms.date: 03/25/2025
1010
---
1111
# Debug WebView2 apps with Visual Studio Code
1212

@@ -28,7 +28,10 @@ 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-
// Customize for your app location if needed.
31+
// The following variable is needed when the "runtimeExecutable" property is set.
32+
// The port number below must match the value of the "port" property above.
33+
"WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS": "--remote-debugging-port=9222"
34+
// Customize for your app location.
3235
"Path": "%path%;e:/path/to/your/app/location; "
3336
},
3437
"useWebView": true,
@@ -39,6 +42,12 @@ The following code demonstrates launching the app from Visual Studio Code (rathe
3942
```
4043

4144

45+
<!-- ---------------------------------- -->
46+
#### Using a registry value
47+
48+
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. For more information, see [WewbView2 browser flags](../concepts/webview-features-flags.md).
49+
50+
4251
<!-- ---------------------------------- -->
4352
#### Command-line URL parameter passed in
4453

@@ -109,8 +118,7 @@ You might need to attach the debugger to running WebView2 processes. To do that
109118
"runtimeExecutable": "C:/path/to/your/webview2/myApp.exe",
110119
"env": {
111120
"Path": "%path%;e:/path/to/your/build/location; "
112-
},
113-
"useWebView": true
121+
}
114122
```
115123

116124
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.
@@ -144,6 +152,12 @@ You also need to add a new REGKEY `<myApp.exe> = --remote-debugging-port=9222` u
144152
![The resulting registry key in the Registry Editor](./debug-visual-studio-code-images/set-debugging-port-registry-key.png)
145153

146154

155+
<!-- ---------------------------------- -->
156+
#### Using an environment variable
157+
158+
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 is started after the environment variable is set, and make sure that your application inherits the environment variable. For more information, see [WewbView2 browser flags](../concepts/webview-features-flags.md).
159+
160+
147161
<!-- ====================================================================== -->
148162
## Debug tracing options
149163

0 commit comments

Comments
 (0)