You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: microsoft-edge/webview2/concepts/working-with-local-content.md
+44-7Lines changed: 44 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ ms.author: msedgedevrel
6
6
ms.topic: conceptual
7
7
ms.service: microsoft-edge
8
8
ms.subservice: webview
9
-
ms.date: 04/10/2024
9
+
ms.date: 02/21/2025
10
10
---
11
11
# Using local content in WebView2 apps
12
12
@@ -353,13 +353,27 @@ When loading local content via a virtual host name mapping, you are mapping a vi
353
353
<!-- ---------- -->
354
354
###### Additional web resources
355
355
356
-
Local content that's loaded via virtual host name mapping has an HTTP or HTTPS URL which supports relative URL resolution. This means that the loaded document can have references to additional web resources such as CSS, script, or image files which are also served via virtual host name mapping.
356
+
Local content that's loaded via virtual host name mapping has an HTTP or HTTPS URL which supports relative URL resolution. This means that the loaded document can have references to additional web resources such as CSS, script, or image files which are also served via virtual host name mapping, except source maps; see [Source maps with virtual host name mapping](#source-maps-with-virtual-host-name-mapping), below.
357
357
358
358
359
359
<!-- ---------- -->
360
360
###### Additional web resources resolved in WebView2 process
361
361
362
-
Virtual host name URLs are resolved in WebView2 processes. This is a faster option than `WebResourceRequested`, which resolves in the host app process UI thread.
362
+
Virtual host name URLs are resolved in WebView2 processes. This is a faster option than `WebResourceRequested`, which resolves in the host app process UI thread.
363
+
364
+
365
+
<!-- ---------- -->
366
+
###### Source maps with virtual host name mapping
367
+
368
+
Source maps are needed to debug the source code of compiled content, including:
369
+
* Transpiled JavaScript, such as TypeScript or minified JavaScript.
370
+
* Compiled CSS, such as SASS or SCSS.
371
+
372
+
WebView2 doesn't load source maps that are referenced by content which was loaded by using virtual host name mapping.
373
+
374
+
For example, suppose WebView2 loads `main.js` via virtual host name mapping. If `main.js` references `main.js.map` as its source map, `main.js.map` will not be loaded automatically.
375
+
376
+
To use source maps along with virtual host name mapping, generate inline source maps during compilation of your content. Inline source maps are embedded within the corresponding compiled file.
## Loading local content by handling the WebResourceRequested event
439
+
## Loading local content by handling the `WebResourceRequested` event
426
440
427
441
Another way you can host local content in a WebView2 control is by relying on the `WebResourceRequested` event. This event is triggered when the control attempts to load a resource. You can use this event to intercept the request and provide the local content, as described in [Custom management of network requests](../how-to/webresourcerequested.md).
428
442
@@ -438,7 +452,7 @@ If you want to use a custom scheme to make the Web Resource Request that generat
438
452
439
453
440
454
<!-- ------------------------------ -->
441
-
#### Considerations for loading local content by handling the WebResourceRequested event
455
+
#### Considerations for loading local content by handling the `WebResourceRequested` event
442
456
443
457
444
458
<!-- ---------- -->
@@ -462,7 +476,7 @@ When loading local content via `WebResourceRequested`, you specify the local con
462
476
<!-- ---------- -->
463
477
###### Additional web resources
464
478
465
-
`WebResourceRequested` modifies the content that's loaded via HTTP or HTTPS URLs, which support relative URL resolution. This means that the resulting document can have references to additional web resources such as CSS, script, or image files that are also served via `WebResourceRequested`.
479
+
`WebResourceRequested` modifies the content that's loaded via HTTP or HTTPS URLs, which support relative URL resolution. This means that the resulting document can have references to additional web resources such as CSS, script, or image files that are also served via `WebResourceRequested`, except source maps; see [Source maps with the `WebResourceRequested` event](#source-maps-with-the-webresourcerequested-event), below.
466
480
467
481
468
482
<!-- ---------- -->
@@ -477,24 +491,47 @@ When loading content via a file URL or a virtual host name mapping, the resoluti
477
491
This can take some time. Make sure to limit calls to `AddWebResourceRequestedFilter` to only the web resources that must raise the `WebResourceRequested` event.
478
492
479
493
494
+
<!-- ---------- -->
495
+
###### Source maps with the `WebResourceRequested` event
496
+
497
+
Source maps are needed to debug the source code of compiled content, including:
498
+
* Transpiled JavaScript, such as TypeScript or minified JavaScript.
499
+
* Compiled CSS, such as SASS or SCSS.
500
+
501
+
WebView2 doesn't load source maps that are referenced by content which was loaded by using the `WebResourceRequested` event.
502
+
503
+
For example, suppose you load `main.js` in your `WebResourceRequested` event handler by setting the `Response` property of `CoreWebView2WebResourceRequestedEventArgs`. If `main.js` references `main.js.map` as its source map:
504
+
* `main.js.map` will not be loaded automatically.
505
+
* Your `WebResourceRequested` event handler will not be called again to load `main.js.map`.
506
+
507
+
To use source maps along with `WebResourceRequested`, use one of the following approaches:
508
+
509
+
* Generate inline source maps during compilation of your content. Inline source maps are embedded within the corresponding compiled file.
510
+
511
+
* Or, inline separate source maps to the content at runtime in your `WebResourceRequested` event handler. Use this approach only if your build system doesn't support inline source maps.
512
+
513
+
480
514
<!-- ------------------------------ -->
481
-
#### APIs for loading local content by handling the WebResourceRequested event
515
+
#### APIs for loading local content by handling the `WebResourceRequested` event
Copy file name to clipboardExpand all lines: microsoft-edge/webview2/how-to/debug-devtools.md
+19-1Lines changed: 19 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ ms.author: msedgedevrel
6
6
ms.topic: conceptual
7
7
ms.service: microsoft-edge
8
8
ms.subservice: webview
9
-
ms.date: 07/07/2022
9
+
ms.date: 02/21/2025
10
10
---
11
11
# Debug WebView2 apps with Microsoft Edge DevTools
12
12
@@ -39,6 +39,24 @@ An app can also use the `OpenDevToolsWindow` API to programmatically open a DevT
39
39
If none of the above approaches are available, you can add `--auto-open-devtools-for-tabs` to the browser arguments via an environment variable or registry key. This approach will open a DevTools window when a WebView2 is created.
## Source maps with the `WebResourceRequested` event or virtual host name mapping
44
+
45
+
Source maps are needed to debug the source code of compiled content, including:
46
+
* Transpiled JavaScript, such as TypeScript or minified JavaScript.
47
+
* Compiled CSS, such as SASS or SCSS.
48
+
49
+
WebView2 doesn't load source maps that are referenced by content which was loaded by using either approach:
50
+
51
+
* The `WebResourceRequested` event. See:
52
+
*[Loading local content by handling the `WebResourceRequested` event](../concepts/working-with-local-content.md#loading-local-content-by-handling-the-webresourcerequested-event) in _Using local content in WebView2 apps_.
53
+
*[Source maps with the `WebResourceRequested` event](../concepts/working-with-local-content.md#source-maps-with-the-webresourcerequested-event) in _Using local content in WebView2 apps_.
54
+
55
+
* Virtual host name mapping. See:
56
+
*[Loading local content by using virtual host name mapping](../concepts/working-with-local-content.md#loading-local-content-by-using-virtual-host-name-mapping) in _Using local content in WebView2 apps_.
57
+
*[Source maps with virtual host name mapping](../concepts/working-with-local-content.md#source-maps-with-virtual-host-name-mapping) in _Using local content in WebView2 apps_.
To debug your code, your project is required to have a `launch.json` file. A `launch.json` file is a debugger configuration file to configure and customize the Visual Studio Code debugger. One of the properties that's needed to configure the debugger is the `request` property. There are two `request` types,`launch` and `attach`.
20
+
To debug your code, your project must have a `launch.json` file. A `launch.json` file is a debugger configuration file to configure and customize the Visual Studio Code debugger. One of the properties that's needed to configure the debugger is the `request` property. There are two `request` types:`launch` and `attach`.
21
21
22
-
The following code demonstrates launching the app from Visual Studio Code (rather than attaching the debugger to a running instance of the app). To do this, the app must have been built previously. If your project doesn't have a `launch.json` file, create a new `launch.json` file in the `.vscode` subfolder in your current project and paste the following code into it:
22
+
The following code demonstrates launching the app from Visual Studio Code (rather than attaching the debugger to a running instance of the app). To do this, the app must have been built previously. If your project doesn't have a `launch.json` file, create a new `launch.json` file in the `.vscode` subfolder in your current project, and paste the following code into it:
23
23
24
24
```json
25
25
"name": "Hello debug world",
@@ -28,12 +28,12 @@ The following code demonstrates launching the app from Visual Studio Code (rathe
@@ -87,7 +87,7 @@ Open `launch.json` and complete the following actions to use targeted WebView2 d
87
87
"urlFilter": "file://C:/path/to/my/index.ts",
88
88
```
89
89
90
-
When debugging your app, you might need to step through the code from the beginning of the rendering process. If you are rendering webpages on sites and you don't have access to the source code, you can use the `?=value` option, because webpages ignore unrecognized parameters.
90
+
When debugging your app, you might need to step through the code from the beginning of the rendering process. If you are rendering webpages on sites and you don't have access to the source code, you can use the `?=value` option, because webpages ignore unrecognized parameters.
91
91
92
92
93
93
<!-- ---------------------------------- -->
@@ -172,7 +172,7 @@ Saving debug output to a log file:
172
172
,"trace": "verbose"// Turn on verbose tracing in the Debug Output pane.
173
173
```
174
174
175
-
Visual Studio Code Debug Output with verbose tracing turned on:
175
+
Visual Studio Code output in the **DEBUG CONSOLE** pane, with verbose tracing turned on:
176
176
177
177

178
178
@@ -219,6 +219,24 @@ If you're debugging Office Add-ins, open the add-in source code in a separate in
219
219

## Source maps with the `WebResourceRequested` event or virtual host name mapping
224
+
225
+
Source maps are needed to debug the source code of compiled content, including:
226
+
* Transpiled JavaScript, such as TypeScript or minified JavaScript.
227
+
* Compiled CSS, such as SASS or SCSS.
228
+
229
+
WebView2 doesn't load source maps that are referenced by content which was loaded by using either approach:
230
+
231
+
* The `WebResourceRequested` event. See:
232
+
*[Loading local content by handling the `WebResourceRequested` event](../concepts/working-with-local-content.md#loading-local-content-by-handling-the-webresourcerequested-event) in _Using local content in WebView2 apps_.
233
+
*[Source maps with the `WebResourceRequested` event](../concepts/working-with-local-content.md#source-maps-with-the-webresourcerequested-event) in _Using local content in WebView2 apps_.
234
+
235
+
* Virtual host name mapping. See:
236
+
*[Loading local content by using virtual host name mapping](../concepts/working-with-local-content.md#loading-local-content-by-using-virtual-host-name-mapping) in _Using local content in WebView2 apps_.
237
+
*[Source maps with virtual host name mapping](../concepts/working-with-local-content.md#source-maps-with-virtual-host-name-mapping) in _Using local content in WebView2 apps_.
Copy file name to clipboardExpand all lines: microsoft-edge/webview2/how-to/debug-visual-studio.md
+19-1Lines changed: 19 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ ms.author: msedgedevrel
6
6
ms.topic: conceptual
7
7
ms.service: microsoft-edge
8
8
ms.subservice: webview
9
-
ms.date: 09/17/2024
9
+
ms.date: 02/21/2025
10
10
---
11
11
# Debug WebView2 apps with Visual Studio
12
12
@@ -161,6 +161,24 @@ After doing the above setup, debug your WebView2 app, as follows.
161
161
The app output shows "This is the very first line of code that executes", because of the line `console.log("This is the very first line of code that executes.");` in the file `WebView2Samples\SampleApps\WebView2APISample\assets\ScenarioJavaScriptDebugIndex.html`.
## Source maps with the `WebResourceRequested` event or virtual host name mapping
166
+
167
+
Source maps are needed to debug the source code of compiled content, including:
168
+
* Transpiled JavaScript, such as TypeScript or minified JavaScript.
169
+
* Compiled CSS, such as SASS or SCSS.
170
+
171
+
WebView2 doesn't load source maps that are referenced by content which was loaded by using either approach:
172
+
173
+
* The `WebResourceRequested` event. See:
174
+
*[Loading local content by handling the `WebResourceRequested` event](../concepts/working-with-local-content.md#loading-local-content-by-handling-the-webresourcerequested-event) in _Using local content in WebView2 apps_.
175
+
*[Source maps with the `WebResourceRequested` event](../concepts/working-with-local-content.md#source-maps-with-the-webresourcerequested-event) in _Using local content in WebView2 apps_.
176
+
177
+
* Virtual host name mapping. See:
178
+
*[Loading local content by using virtual host name mapping](../concepts/working-with-local-content.md#loading-local-content-by-using-virtual-host-name-mapping) in _Using local content in WebView2 apps_.
179
+
*[Source maps with virtual host name mapping](../concepts/working-with-local-content.md#source-maps-with-virtual-host-name-mapping) in _Using local content in WebView2 apps_.
0 commit comments