@@ -6,6 +6,14 @@ self-hosted.
6
6
When doing this CSP will block resources (for example when viewing images) so
7
7
add 'self' to the CSP to fix that.
8
8
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
+
9
17
Index: code-server/lib/vscode/src/vs/workbench/services/environment/browser/environmentService.ts
10
18
===================================================================
11
19
--- 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
44
52
45
53
/**
46
54
* 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