diff --git a/src/server/trace/recorder/tracing.ts b/src/server/trace/recorder/tracing.ts index 86058bb2f0..11febc57e4 100644 --- a/src/server/trace/recorder/tracing.ts +++ b/src/server/trace/recorder/tracing.ts @@ -38,7 +38,7 @@ export type TracerOptions = { screenshots?: boolean; }; -export const VERSION = 2; +export const VERSION = 3; type RecordingState = { options: TracerOptions, diff --git a/src/server/trace/viewer/traceModel.ts b/src/server/trace/viewer/traceModel.ts index e463c816d0..bf960821c0 100644 --- a/src/server/trace/viewer/traceModel.ts +++ b/src/server/trace/viewer/traceModel.ts @@ -130,6 +130,32 @@ export class TraceModel { } return event; } + + _modernize_2_to_3(event: any): any { + if (event.type === 'resource-snapshot' && !event.snapshot.request) { + // Migrate from old ResourceSnapshot to new har entry format. + const resource = event.snapshot; + event.snapshot = { + _frameref: resource.frameId, + request: { + url: resource.url, + method: resource.method, + headers: resource.requestHeaders, + postData: resource.requestSha1 ? { _sha1: resource.requestSha1 } : undefined, + }, + response: { + status: resource.status, + headers: resource.responseHeaders, + content: { + mimeType: resource.contentType, + _sha1: resource.responseSha1, + }, + }, + _monotonicTime: resource.timestamp, + }; + } + return event; + } } export type ContextEntry = { diff --git a/src/server/trace/viewer/traceViewer.ts b/src/server/trace/viewer/traceViewer.ts index bcaf342d6c..18e618187e 100644 --- a/src/server/trace/viewer/traceViewer.ts +++ b/src/server/trace/viewer/traceViewer.ts @@ -83,7 +83,8 @@ export class TraceViewer { const networkFile = path.join(tracesDir, (match ? match[1] : debugName) + '.network'); const model = new TraceModel(snapshotStorage); await appendTraceEvents(model, traceFile); - await appendTraceEvents(model, networkFile); + if (fs.existsSync(networkFile)) + await appendTraceEvents(model, networkFile); model.build(); response.end(JSON.stringify(model.contextEntry)); })().catch(e => console.error(e));