@@ -6,6 +6,17 @@ 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 handling *all* requests made to the
10
+ current host but when self-hosting the webview this will end up including the
11
+ webview HTML itself which means these requests will fail since the communication
12
+ channel between the webview and the main thread has not been set up yet as the
13
+ webview itself is not ready yet (it has no HTML and therefore no script either).
14
+ Since this code exists only for the authentication case we can just skip it when
15
+ it is served from the current host as authentication is not a problem if the
16
+ request is not cross-origin.
17
+
18
+ To test, open a few types of webviews (images, markdown, extension details, etc).
19
+
9
20
Index: code-server/lib/vscode/src/vs/workbench/services/environment/browser/environmentService.ts
10
21
===================================================================
11
22
--- code-server.orig/lib/vscode/src/vs/workbench/services/environment/browser/environmentService.ts
@@ -44,3 +55,22 @@ Index: code-server/lib/vscode/src/vs/workbench/common/webview.ts
44
55
45
56
/**
46
57
* Construct a uri that can load resources inside a webview
58
+ Index: code-server/lib/vscode/src/vs/workbench/contrib/webview/browser/pre/service-worker.js
59
+ ===================================================================
60
+ --- code-server.orig/lib/vscode/src/vs/workbench/contrib/webview/browser/pre/service-worker.js
61
+ +++ code-server/lib/vscode/src/vs/workbench/contrib/webview/browser/pre/service-worker.js
62
+ @@ -188,9 +188,11 @@ sw.addEventListener('fetch', (event) =>
63
+ }
64
+ }
65
+
66
+ - // If we're making a request against the remote authority, we want to go
67
+ - // back through VS Code itself so that we are authenticated properly
68
+ - if (requestUrl.host === remoteAuthority) {
69
+ + // If we're making a request against the remote authority, we want to go back
70
+ + // through VS Code itself so that we are authenticated properly. If the
71
+ + // service worker is hosted on the same origin we will have cookies and
72
+ + // authentication will not be an issue.
73
+ + if (requestUrl.origin !== sw.origin && requestUrl.host === remoteAuthority) {
74
+ switch (event.request.method) {
75
+ case 'GET':
76
+ case 'HEAD':
0 commit comments