fix(trace-viewer): do not rely upon request mode, it is inconsistent (#10198)
This commit is contained in:
parent
75efeb1e08
commit
0d0f1690cd
|
|
@ -51,19 +51,18 @@ async function loadTrace(trace: string, clientId: string, progress: (done: numbe
|
||||||
async function doFetch(event: FetchEvent): Promise<Response> {
|
async function doFetch(event: FetchEvent): Promise<Response> {
|
||||||
const request = event.request;
|
const request = event.request;
|
||||||
const client = await self.clients.get(event.clientId);
|
const client = await self.clients.get(event.clientId);
|
||||||
const snapshotUrl = request.mode === 'navigate' ? request.url : client!.url;
|
|
||||||
const traceUrl = new URL(snapshotUrl).searchParams.get('trace')!;
|
|
||||||
const { snapshotServer } = loadedTraces.get(traceUrl) || {};
|
|
||||||
|
|
||||||
if (request.url.startsWith(self.registration.scope)) {
|
if (request.url.startsWith(self.registration.scope)) {
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
|
|
||||||
const relativePath = url.pathname.substring(scopePath.length - 1);
|
const relativePath = url.pathname.substring(scopePath.length - 1);
|
||||||
if (relativePath === '/ping') {
|
if (relativePath === '/ping') {
|
||||||
await gc();
|
await gc();
|
||||||
return new Response(null, { status: 200 });
|
return new Response(null, { status: 200 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const traceUrl = new URL(url).searchParams.get('trace')!;
|
||||||
|
const { snapshotServer } = loadedTraces.get(traceUrl) || {};
|
||||||
|
|
||||||
if (relativePath === '/context') {
|
if (relativePath === '/context') {
|
||||||
const traceModel = await loadTrace(traceUrl, event.clientId, (done: number, total: number) => {
|
const traceModel = await loadTrace(traceUrl, event.clientId, (done: number, total: number) => {
|
||||||
client.postMessage({ method: 'progress', params: { done, total } });
|
client.postMessage({ method: 'progress', params: { done, total } });
|
||||||
|
|
@ -83,7 +82,7 @@ async function doFetch(event: FetchEvent): Promise<Response> {
|
||||||
if (relativePath.startsWith('/snapshot/')) {
|
if (relativePath.startsWith('/snapshot/')) {
|
||||||
if (!snapshotServer)
|
if (!snapshotServer)
|
||||||
return new Response(null, { status: 404 });
|
return new Response(null, { status: 404 });
|
||||||
return snapshotServer.serveSnapshot(relativePath, url.searchParams, snapshotUrl);
|
return snapshotServer.serveSnapshot(relativePath, url.searchParams, request.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (relativePath.startsWith('/sha1/')) {
|
if (relativePath.startsWith('/sha1/')) {
|
||||||
|
|
@ -100,6 +99,9 @@ async function doFetch(event: FetchEvent): Promise<Response> {
|
||||||
return fetch(event.request);
|
return fetch(event.request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const snapshotUrl = client!.url;
|
||||||
|
const traceUrl = new URL(snapshotUrl).searchParams.get('trace')!;
|
||||||
|
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);
|
return snapshotServer.serveResource(request.url, snapshotUrl);
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ export const Workbench: React.FunctionComponent<{
|
||||||
{dragOver && <div className='drop-target'
|
{dragOver && <div className='drop-target'
|
||||||
onDragLeave={() => { setDragOver(false); }}
|
onDragLeave={() => { setDragOver(false); }}
|
||||||
onDrop={event => handleDropEvent(event)}>
|
onDrop={event => handleDropEvent(event)}>
|
||||||
Release to analyse the Playwright Trace
|
<div className='title'>Release to analyse the Playwright Trace</div>
|
||||||
</div>}
|
</div>}
|
||||||
</div>;
|
</div>;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,8 @@ const test = baseTest.extend<{ showReport: () => Promise<void> }>({
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test.use({ channel: 'chrome' });
|
||||||
|
|
||||||
test('should generate report', async ({ runInlineTest, showReport, page }) => {
|
test('should generate report', async ({ runInlineTest, showReport, page }) => {
|
||||||
await runInlineTest({
|
await runInlineTest({
|
||||||
'playwright.config.ts': `
|
'playwright.config.ts': `
|
||||||
Loading…
Reference in a new issue