From a3af0829ffd5f50387f102e62d07233e62754a9f Mon Sep 17 00:00:00 2001 From: Dominik Deren Date: Tue, 26 Jan 2021 20:06:05 +0100 Subject: [PATCH] feat(trace viewer): Extending existing NetworkTab view (#5009) feat(trace viewer): Extending existing NetworkTab view Currently the network tab contains a limited amount of information on the resources that were loaded in the browser. This change proposes extending the details displayed for each resource, to include: - HTTP method, - Full url, - Easily visible response content type, - Request headers, - Request & response bodies. Such level of information could help quickly understand what happened in the application, when it was communicating with backend services. This can help debug tests quicker to figure out why they are failing. This implementation still needs some clean up & tests improvement, but I wanted to propose such changes and gather your feedback before going too far. --- src/cli/traceViewer/snapshotRouter.ts | 2 +- src/cli/traceViewer/traceViewer.ts | 6 + src/cli/traceViewer/web/index.tsx | 1 + src/cli/traceViewer/web/styles.tsx | 2 + src/cli/traceViewer/web/ui/helpers.tsx | 5 +- .../web/ui/networkResourceDetails.css | 112 +++++++++++++++++ .../web/ui/networkResourceDetails.tsx | 116 ++++++++++++++++++ src/cli/traceViewer/web/ui/networkTab.css | 42 ------- src/cli/traceViewer/web/ui/networkTab.tsx | 15 +-- src/trace/snapshotter.ts | 23 +++- src/trace/traceTypes.ts | 6 +- src/trace/tracer.ts | 6 +- test/assets/trace-resources.html | 19 +++ test/trace.spec.ts | 56 ++++++++- 14 files changed, 349 insertions(+), 62 deletions(-) create mode 100644 src/cli/traceViewer/web/ui/networkResourceDetails.css create mode 100644 src/cli/traceViewer/web/ui/networkResourceDetails.tsx create mode 100644 test/assets/trace-resources.html diff --git a/src/cli/traceViewer/snapshotRouter.ts b/src/cli/traceViewer/snapshotRouter.ts index 6b4127ea7bd7d..f8e4ee1eb4dec 100644 --- a/src/cli/traceViewer/snapshotRouter.ts +++ b/src/cli/traceViewer/snapshotRouter.ts @@ -169,7 +169,7 @@ export class SnapshotRouter { } private async _readResource(event: trace.NetworkResourceTraceEvent, overrideSha1: string | undefined) { - const body = await this._readSha1(overrideSha1 || event.sha1); + const body = await this._readSha1(overrideSha1 || event.responseSha1); if (!body) return; return { diff --git a/src/cli/traceViewer/traceViewer.ts b/src/cli/traceViewer/traceViewer.ts index 96a5419ec43fa..bcac6955538bf 100644 --- a/src/cli/traceViewer/traceViewer.ts +++ b/src/cli/traceViewer/traceViewer.ts @@ -92,6 +92,12 @@ class TraceViewer { await uiPage.exposeBinding('readFile', async (_, path: string) => { return fs.readFileSync(path).toString(); }); + await uiPage.exposeBinding('readResource', async (_, sha1: string) => { + if (!this._document) + return; + + return fs.readFileSync(path.join(this._document.resourcesDir, sha1)).toString('base64'); + }); await uiPage.exposeBinding('renderSnapshot', async (_, arg: { action: ActionTraceEvent, snapshot: { name: string, snapshotId?: string } }) => { const { action, snapshot } = arg; if (!this._document) diff --git a/src/cli/traceViewer/web/index.tsx b/src/cli/traceViewer/web/index.tsx index 264b5cf55fb48..fae79c76f2613 100644 --- a/src/cli/traceViewer/web/index.tsx +++ b/src/cli/traceViewer/web/index.tsx @@ -25,6 +25,7 @@ declare global { interface Window { getTraceModel(): Promise; readFile(filePath: string): Promise; + readResource(sha1: string): Promise; renderSnapshot(arg: { action: trace.ActionTraceEvent, snapshot: { name: string, snapshotId?: string } }): void; } } diff --git a/src/cli/traceViewer/web/styles.tsx b/src/cli/traceViewer/web/styles.tsx index 5c55b48cd8e96..dcc0aa488cdd5 100644 --- a/src/cli/traceViewer/web/styles.tsx +++ b/src/cli/traceViewer/web/styles.tsx @@ -26,6 +26,7 @@ export const GlobalStyles = () =>