update PR

This commit is contained in:
Simon Knott 2024-11-11 12:30:52 +01:00
parent a8dbc0fdd8
commit d07d8f0fbe
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC

View file

@ -76,7 +76,7 @@ async function doFetch(event: FetchEvent): Promise<Response> {
return fetch(event.request); return fetch(event.request);
const request = event.request; const request = event.request;
const client = await self.clients.get(event.clientId); const client = await self.clients.get(event.clientId ?? event.resultingClientId);
// When trace viewer is deployed over https, we will force upgrade // When trace viewer is deployed over https, we will force upgrade
// insecure http subresources to https. Otherwise, these will fail // insecure http subresources to https. Otherwise, these will fail
@ -96,6 +96,9 @@ async function doFetch(event: FetchEvent): Promise<Response> {
const traceUrl = url.searchParams.get('trace'); const traceUrl = url.searchParams.get('trace');
if (relativePath.startsWith('/snapshot/')) { if (relativePath.startsWith('/snapshot/')) {
// while there's no snapshot, the iframe keeps polling but isn't yet initialised.
// `event.resultingClientId` will contain an ID, but it won't yet be available in `self.clients`.
// so `client` will be undefined in that state.
const { snapshotServer } = loadedTraces.get(traceUrl!) || {}; const { snapshotServer } = loadedTraces.get(traceUrl!) || {};
if (!snapshotServer) if (!snapshotServer)
return new Response(null, { status: 404 }); return new Response(null, { status: 404 });
@ -105,13 +108,6 @@ async function doFetch(event: FetchEvent): Promise<Response> {
return response; return response;
} }
if (relativePath.startsWith('/closest-screenshot/')) {
const { snapshotServer } = loadedTraces.get(traceUrl!) || {};
if (!snapshotServer)
return new Response(null, { status: 404 });
return snapshotServer.serveClosestScreenshot(relativePath, url.searchParams);
}
if (!client) { if (!client) {
// vscode webview doesn't sent clientId under some circumstances // vscode webview doesn't sent clientId under some circumstances
if (url.pathname.endsWith('embedded.html')) if (url.pathname.endsWith('embedded.html'))
@ -144,6 +140,13 @@ async function doFetch(event: FetchEvent): Promise<Response> {
return snapshotServer.serveSnapshotInfo(relativePath, url.searchParams); return snapshotServer.serveSnapshotInfo(relativePath, url.searchParams);
} }
if (relativePath.startsWith('/closest-screenshot/')) {
const { snapshotServer } = loadedTraces.get(traceUrl!) || {};
if (!snapshotServer)
return new Response(null, { status: 404 });
return snapshotServer.serveClosestScreenshot(relativePath, url.searchParams);
}
if (relativePath.startsWith('/sha1/')) { if (relativePath.startsWith('/sha1/')) {
// Sha1 for sources is based on the file path, can't load it of a random model. // Sha1 for sources is based on the file path, can't load it of a random model.
const sha1 = relativePath.slice('/sha1/'.length); const sha1 = relativePath.slice('/sha1/'.length);