Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix(har): recognize `.zip` extensions regardless of case (#43550)
Devin Roussoe78ff90d4ca8
diff --git a/packages/playwright-core/src/client/browserContext.ts b/packages/playwright-core/src/client/browserContext.tsindex 983a96fa11..82bda57288 100644--- a/packages/playwright-core/src/client/browserContext.ts+++ b/packages/playwright-core/src/client/browserContext.ts@@ -191,7 +191,7 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel>async _initializeHarFromOptions(recordHar: BrowserContextOptions['recordHar']) {if (!recordHar)return;- const defaultContent = recordHar.path.endsWith('.zip') ? 'attach' : 'embed';+ const defaultContent = /\.zip$/i.test(recordHar.path) ? 'attach' : 'embed';await this.tracing._recordIntoHAR(recordHar.path, null, {url: recordHar.urlFilter,updateContent: recordHar.content ?? (recordHar.omitContent ? 'omit' : defaultContent),diff --git a/packages/playwright-core/src/client/tracing.ts b/packages/playwright-core/src/client/tracing.tsindex db9477a41e..2fae3fc93a 100644--- a/packages/playwright-core/src/client/tracing.ts+++ b/packages/playwright-core/src/client/tracing.ts@@ -105,9 +105,9 @@ export class Tracing extends ChannelOwner<channels.TracingChannel> implements apasync startHar(path: string, options: { content?: 'embed' | 'attach' | 'omit', mode?: 'full' | 'minimal', urlFilter?: string | RegExp, resourcesDir?: string } = {}) {if (this._harId)throw new Error('HAR recording has already been started');- if (options.resourcesDir && path.endsWith('.zip'))+ if (options.resourcesDir && /\.zip$/i.test(path))throw new Error('resourcesDir option is not compatible with a .zip har file');- const defaultContent = path.endsWith('.zip') ? 'attach' : 'embed';+ const defaultContent = /\.zip$/i.test(path) ? 'attach' : 'embed';this._harId = await this._recordIntoHAR(path, null, {url: options.urlFilter,updateContent: options.content ?? defaultContent,@@ -127,7 +127,7 @@ export class Tracing extends ChannelOwner<channels.TracingChannel> implements ap}async _recordIntoHAR(har: string, page: Page | null, options: { url?: string | RegExp, updateContent?: 'attach' | 'embed' | 'omit', updateMode?: 'minimal' | 'full', resourcesDir?: string } = {}): Promise<string> {- const isZip = har.endsWith('.zip');+ const isZip = /\.zip$/i.test(har);const { harId } = await this._channel.harStart({page: page?._channel,options: {@@ -150,7 +150,7 @@ export class Tracing extends ChannelOwner<channels.TracingChannel> implements apreturn;this._harRecorders.delete(harId);const isLocal = !this._connection.isRemote();- const isZip = harParams.path.endsWith('.zip');+ const isZip = /\.zip$/i.test(harParams.path);if (isLocal) {const { entries } = await this._channel.harExport({ harId, mode: 'entries' }, kNoTimeout);diff --git a/packages/playwright-core/src/server/localUtils.ts b/packages/playwright-core/src/server/localUtils.tsindex b564feffc8..df62972b27 100644--- a/packages/playwright-core/src/server/localUtils.ts+++ b/packages/playwright-core/src/server/localUtils.ts@@ -149,7 +149,7 @@ async function deleteStackSession(progress: Progress, stackSessions: Map<string,export async function harOpen(progress: Progress, harBackends: Map<string, HarBackend>, params: channels.LocalUtilsHarOpenParams): Promise<channels.LocalUtilsHarOpenResult> {let harBackend: HarBackend;- if (params.file.endsWith('.zip')) {+ if (/\.zip$/i.test(params.file)) {const zipFile = new ZipFile(params.file);try {const entryNames = await progress.race(zipFile.entries());diff --git a/tests/library/browsercontext-har.spec.ts b/tests/library/browsercontext-har.spec.tsindex 2b0c42e4f1..8ae9a552a9 100644--- a/tests/library/browsercontext-har.spec.ts+++ b/tests/library/browsercontext-har.spec.ts@@ -241,13 +241,20 @@ it('HA-084 should fulfill from har with content in a file', async ({ context, asexpect(await page.content()).toBe('<html><head></head><body>Hello, world</body></html>');});-it('HA-085 should round-trip har.zip', async ({ contextFactory, server }, testInfo) => {- const harPath = testInfo.outputPath('har.zip');+it('HA-085 should round-trip har.zip', {+ annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43503' },+}, async ({ contextFactory, server }, testInfo) => {+ const harPath = testInfo.outputPath('har.ZIP');const context1 = await contextFactory({ recordHar: { mode: 'minimal', path: harPath } });const page1 = await context1.newPage();await page1.goto(server.PREFIX + '/one-style.html');await context1.close();+ const harDir = testInfo.outputPath('har');+ await extractZip(harPath, { dir: harDir });+ const { log } = JSON.parse(fs.readFileSync(path.join(harDir, 'har.har'), 'utf-8'));+ expect(log.entries[0].response.content._file).toEqual(expect.any(String));+const context2 = await contextFactory();await context2.routeFromHAR(harPath, { notFound: 'abort' });const page2 = await context2.newPage();