Skip to content

Commit 4f71c0e

Browse files
committed
Fix webviews failing to load the iframe HTML
Code added in 1.65.0 broke webviews when you are hosting them from the same domain.
1 parent e7e6c16 commit 4f71c0e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

patches/webview.diff

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ self-hosted.
66
When doing this CSP will block resources (for example when viewing images) so
77
add 'self' to the CSP to fix that.
88

9+
Additionally the service worker defaults to always trying to handle any requests
10+
made to the current host but this will include the webview HTML itself which
11+
means these requests will fail since the communication channel between the
12+
webview and the main thread has not been set up yet so patch the service worker
13+
to skip handling requests for other webview assets.
14+
15+
To test, open a few types of webviews (images, markdown, extension details, etc).
16+
917
Index: code-server/lib/vscode/src/vs/workbench/services/environment/browser/environmentService.ts
1018
===================================================================
1119
--- code-server.orig/lib/vscode/src/vs/workbench/services/environment/browser/environmentService.ts
@@ -44,3 +52,23 @@ Index: code-server/lib/vscode/src/vs/workbench/common/webview.ts
4452

4553
/**
4654
* Construct a uri that can load resources inside a webview
55+
Index: code-server/lib/vscode/src/vs/workbench/contrib/webview/browser/pre/service-worker.js
56+
===================================================================
57+
--- code-server.orig/lib/vscode/src/vs/workbench/contrib/webview/browser/pre/service-worker.js
58+
+++ code-server/lib/vscode/src/vs/workbench/contrib/webview/browser/pre/service-worker.js
59+
@@ -188,9 +188,12 @@ sw.addEventListener('fetch', (event) =>
60+
}
61+
}
62+
63+
- // If we're making a request against the remote authority, we want to go
64+
- // back through VS Code itself so that we are authenticated properly
65+
- if (requestUrl.host === remoteAuthority) {
66+
+ // If we're making a request against the remote authority, we want to go back
67+
+ // through VS Code itself so that we are authenticated properly. Requests to
68+
+ // other static assets in this directory (like the iframe HTML) must be
69+
+ // fetched normally since there will not yet be a communication channel set up
70+
+ // to retrieve them (they do not require authentication anyway).
71+
+ if (requestUrl.host === remoteAuthority && !requestUrl.pathname.startsWith(rootPath)) {
72+
switch (event.request.method) {
73+
case 'GET':
74+
case 'HEAD':

0 commit comments

Comments
 (0)