fix(trace viewer): allow http/https mismatch when deployed as https (#21289)
References #21263.
This commit is contained in:
parent
933332ad97
commit
b343d453bc
|
|
@ -17,6 +17,7 @@
|
||||||
import type { SnapshotStorage } from './snapshotStorage';
|
import type { SnapshotStorage } from './snapshotStorage';
|
||||||
import type { URLSearchParams } from 'url';
|
import type { URLSearchParams } from 'url';
|
||||||
import type { SnapshotRenderer } from './snapshotRenderer';
|
import type { SnapshotRenderer } from './snapshotRenderer';
|
||||||
|
import type { ResourceSnapshot } from '@trace/snapshot';
|
||||||
|
|
||||||
type Point = { x: number, y: number };
|
type Point = { x: number, y: number };
|
||||||
|
|
||||||
|
|
@ -62,10 +63,14 @@ export class SnapshotServer {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async serveResource(requestUrl: string, snapshotUrl: string): Promise<Response> {
|
async serveResource(requestUrlAlternatives: string[], snapshotUrl: string): Promise<Response> {
|
||||||
|
let resource: ResourceSnapshot | undefined;
|
||||||
const snapshot = this._snapshotIds.get(snapshotUrl)!;
|
const snapshot = this._snapshotIds.get(snapshotUrl)!;
|
||||||
const url = removeHash(requestUrl);
|
for (const requestUrl of requestUrlAlternatives) {
|
||||||
const resource = snapshot?.resourceByUrl(url);
|
resource = snapshot?.resourceByUrl(removeHash(requestUrl));
|
||||||
|
if (resource)
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (!resource)
|
if (!resource)
|
||||||
return new Response(null, { status: 404 });
|
return new Response(null, { status: 404 });
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -124,7 +124,14 @@ async function doFetch(event: FetchEvent): Promise<Response> {
|
||||||
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 });
|
||||||
return snapshotServer.serveResource(request.url, snapshotUrl);
|
|
||||||
|
const lookupUrls = [request.url];
|
||||||
|
// When trace viewer is deployed over https, Chrome changes http subresources
|
||||||
|
// in snapshots to https, presumably to avoid mixed-content.
|
||||||
|
// In this case, we additionally match http resources from the archive.
|
||||||
|
if (self.registration.scope.startsWith('https://') && request.url.startsWith('https://'))
|
||||||
|
lookupUrls.push(request.url.replace(/^https/, 'http'));
|
||||||
|
return snapshotServer.serveResource(lookupUrls, snapshotUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function gc() {
|
async function gc() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue