From f4a986e61afb67c9d9497c3132cc083a819d3ae6 Mon Sep 17 00:00:00 2001 From: Simon Knott Date: Tue, 17 Sep 2024 15:48:37 +0200 Subject: [PATCH] omit timings --- .../playwright-core/src/server/har/harTracer.ts | 6 ++++-- tests/library/har.spec.ts | 17 +++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/playwright-core/src/server/har/harTracer.ts b/packages/playwright-core/src/server/har/harTracer.ts index 077777ff34..76da6682d4 100644 --- a/packages/playwright-core/src/server/har/harTracer.ts +++ b/packages/playwright-core/src/server/har/harTracer.ts @@ -213,8 +213,10 @@ export class HarTracer { harEntry.response.httpVersion = event.httpVersion; harEntry.response.redirectURL = event.headers.location || ''; - harEntry.timings = event.timings; - this._computeHarEntryTotalTime(harEntry); + if (!this._options.omitTiming) { + harEntry.timings = event.timings; + this._computeHarEntryTotalTime(harEntry); + } for (let i = 0; i < event.rawHeaders.length; i += 2) { harEntry.response.headers.push({ diff --git a/tests/library/har.spec.ts b/tests/library/har.spec.ts index 5f2865226f..cc65127e3f 100644 --- a/tests/library/har.spec.ts +++ b/tests/library/har.spec.ts @@ -24,9 +24,9 @@ import type { Log } from '../../packages/trace/src/har'; import { parseHar } from '../config/utils'; const { createHttp2Server } = require('../../packages/playwright-core/lib/utils'); -async function pageWithHar(contextFactory: (options?: BrowserContextOptions) => Promise, testInfo: any, options: { outputPath?: string, content?: 'embed' | 'attach' | 'omit', omitContent?: boolean } = {}) { +async function pageWithHar(contextFactory: (options?: BrowserContextOptions) => Promise, testInfo: any, options: { outputPath?: string } & Partial> = {}) { const harPath = testInfo.outputPath(options.outputPath || 'test.har'); - const context = await contextFactory({ recordHar: { path: harPath, content: options.content, omitContent: options.omitContent }, ignoreHTTPSErrors: true }); + const context = await contextFactory({ recordHar: { path: harPath, ...options }, ignoreHTTPSErrors: true }); const page = await context.newPage(); return { page, @@ -833,6 +833,19 @@ it('should include API request', async ({ contextFactory, server }, testInfo) => })); }); +it('should respect minimal mode for API Requests', async ({ contextFactory, server }, testInfo) => { + const { page, getLog } = await pageWithHar(contextFactory, testInfo, { mode: 'minimal' }); + const url = server.PREFIX + '/simple.json'; + await page.request.post(url, { + headers: { cookie: 'a=b; c=d' }, + data: { foo: 'bar' } + }); + const { entries } = await getLog(); + expect(entries).toHaveLength(1); + const [entry] = entries; + expect(entry.timings).toEqual({ receive: -1, send: -1, wait: -1 }); +}); + it('should include redirects from API request', async ({ contextFactory, server }, testInfo) => { server.setRedirect('/redirect-me', '/simple.json'); const { page, getLog } = await pageWithHar(contextFactory, testInfo);