From 0ebe090b8c6ec596f45fed8645f73a942dad92b0 Mon Sep 17 00:00:00 2001 From: Yury Semikhatsky Date: Fri, 3 Mar 2023 17:27:34 -0800 Subject: [PATCH] fix(har): do not hang on chunked response in har recorder (#21397) Fixes #21182 --- .../src/server/har/harTracer.ts | 31 ++++++++++--------- tests/library/har.spec.ts | 1 - 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/packages/playwright-core/src/server/har/harTracer.ts b/packages/playwright-core/src/server/har/harTracer.ts index 60a44ddf65..8629d6be31 100644 --- a/packages/playwright-core/src/server/har/harTracer.ts +++ b/packages/playwright-core/src/server/har/harTracer.ts @@ -289,6 +289,23 @@ export class HarTracer { return; const page = request.frame()?._page; + // In WebKit security details and server ip are reported in Network.loadingFinished, so we populate + // it here to not hang in case of long chunked responses, see https://github.com/microsoft/playwright/issues/21182. + if (!this._options.omitServerIP) { + this._addBarrier(page || request.serviceWorker(), response.serverAddr().then(server => { + if (server?.ipAddress) + harEntry.serverIPAddress = server.ipAddress; + if (server?.port) + harEntry._serverPort = server.port; + })); + } + if (!this._options.omitSecurityDetails) { + this._addBarrier(page || request.serviceWorker(), response.securityDetails().then(details => { + if (details) + harEntry._securityDetails = details; + })); + } + const httpVersion = response.httpVersion(); harEntry.request.httpVersion = httpVersion; harEntry.response.httpVersion = httpVersion; @@ -435,20 +452,6 @@ export class HarTracer { this._computeHarEntryTotalTime(harEntry); } - if (!this._options.omitServerIP) { - this._addBarrier(page || request.serviceWorker(), response.serverAddr().then(server => { - if (server?.ipAddress) - harEntry.serverIPAddress = server.ipAddress; - if (server?.port) - harEntry._serverPort = server.port; - })); - } - if (!this._options.omitSecurityDetails) { - this._addBarrier(page || request.serviceWorker(), response.securityDetails().then(details => { - if (details) - harEntry._securityDetails = details; - })); - } this._recordRequestOverrides(harEntry, request); this._addBarrier(page || request.serviceWorker(), request.rawRequestHeaders().then(headers => { this._recordRequestHeadersAndCookies(harEntry, headers); diff --git a/tests/library/har.spec.ts b/tests/library/har.spec.ts index 5c66c83849..0a0e911f68 100644 --- a/tests/library/har.spec.ts +++ b/tests/library/har.spec.ts @@ -831,7 +831,6 @@ it('should not hang on resources served from cache', async ({ contextFactory, se it('should not hang on slow chunked response', async ({ browserName, browser, contextFactory, server }, testInfo) => { it.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/21182' }); - it.fixme(browserName === 'webkit'); server.setRoute('/empty.html', (req, res) => { res.writeHead(200, { 'Content-Type': 'text/html',