Skip to content

Commit 25b1934

Browse files
authored
Fix error loading webview service worker on Chrome (#8773)
Port of #8770 to the main branch.
1 parent a8d2299 commit 25b1934

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

build/secrets/.secrets.baseline

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,7 +1711,7 @@
17111711
{
17121712
"type": "Base64 High Entropy String",
17131713
"filename": "src/vs/workbench/contrib/webview/browser/pre/index.html",
1714-
"hashed_secret": "8f848d45aabb6a8b8da85a44943af7f622b9ade3",
1714+
"hashed_secret": "e7a023150065e25d74a3ef59bdedb85e9f3f42c5",
17151715
"is_verified": false,
17161716
"line_number": 9,
17171717
"is_secret": false
@@ -1786,5 +1786,5 @@
17861786
}
17871787
]
17881788
},
1789-
"generated_at": "2025-07-30T21:02:03Z"
1789+
"generated_at": "2025-07-31T20:07:12Z"
17901790
}

src/vs/server/node/remoteExtensionHostAgentServer.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -164,23 +164,10 @@ class RemoteExtensionHostAgentServer extends Disposable implements IServerAPI {
164164
return void res.end('OK');
165165
}
166166

167-
// --- Start PWB ---
168-
// Validate the connection token for all requests except the webview
169-
// service worker.
170-
//
171-
// When the browser requests the service worker (loaded from index.html
172-
// in browser/pre), it can omit the connection token cookie, causing the
173-
// server to reject the request here.
174-
//
175-
// Upstream VS Code doesn't have this problem since the webview and
176-
// service worker aren't served from this codepath at all but from a CDN.
177-
if (pathname.indexOf('/service-worker.js') === -1) {
178-
if (!httpRequestHasValidConnectionToken(this._connectionToken, req, parsedUrl)) {
179-
// invalid connection token
180-
return serveError(req, res, 403, `Forbidden.`);
181-
}
167+
if (!httpRequestHasValidConnectionToken(this._connectionToken, req, parsedUrl)) {
168+
// invalid connection token
169+
return serveError(req, res, 403, `Forbidden.`);
182170
}
183-
// --- End PWB ---
184171

185172
if (pathname === '/vscode-remote-resource') {
186173
// Handle HTTP requests for resources rendered in the rich client (images, fonts, etc.)

src/vs/workbench/contrib/webview/browser/pre/index.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<!-- Start PWB: serve same origin -->
88
<meta http-equiv="Content-Security-Policy"
9-
content="default-src 'none'; script-src 'sha256-/qgqbHEZCrIqUOyxf4kxCym0Svcu9WOma3qHTPUldD4=' 'self'; frame-src 'self'; style-src 'unsafe-inline';">
9+
content="default-src 'none'; script-src 'sha256-NPpZhEvmG5f+y/SzFPmY5Y/Iyy6dC4HC9nONtQig/h0=' 'self'; frame-src 'self'; style-src 'unsafe-inline';">
1010
<!-- End PWB: serve same origin -->
1111

1212
<!-- Disable pinch zooming -->
@@ -239,8 +239,15 @@
239239
return reject(new Error('Service Workers are not enabled. Webviews will not work. Try disabling private/incognito mode.'));
240240
}
241241

242+
// --- Start Positron ---
243+
// Remove { type: 'module' } from service worker registration options. On Chrome, this causes
244+
// the browser to make the request for the service worker without any cookies attached, which
245+
// causes the request to fail.
246+
//
247+
// Upstream VS Code doesn't have this issue since it loads this file from a CDN.
242248
const swPath = encodeURI(`service-worker.js?v=${expectedWorkerVersion}&vscode-resource-base-authority=${searchParams.get('vscode-resource-base-authority')}&remoteAuthority=${searchParams.get('remoteAuthority') ?? ''}`);
243-
navigator.serviceWorker.register(swPath, { type: 'module' })
249+
navigator.serviceWorker.register(swPath)
250+
// --- End Positron ---
244251
.then(async registration => {
245252
/**
246253
* @param {MessageEvent} event

0 commit comments

Comments
 (0)