Skip to content

Commit d57b439

Browse files
authored
fix(har): support har in persistent context (#4322)
1 parent 924cc98 commit d57b439

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

src/protocol/channels.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ export type BrowserTypeLaunchPersistentContextParams = {
272272
height: number,
273273
},
274274
},
275+
recordHar?: {
276+
omitContent?: boolean,
277+
path: string,
278+
},
275279
};
276280
export type BrowserTypeLaunchPersistentContextOptions = {
277281
executablePath?: string,
@@ -337,6 +341,10 @@ export type BrowserTypeLaunchPersistentContextOptions = {
337341
height: number,
338342
},
339343
},
344+
recordHar?: {
345+
omitContent?: boolean,
346+
path: string,
347+
},
340348
};
341349
export type BrowserTypeLaunchPersistentContextResult = {
342350
context: BrowserContextChannel,

src/protocol/protocol.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,11 @@ BrowserType:
325325
properties:
326326
width: number
327327
height: number
328+
recordHar:
329+
type: object?
330+
properties:
331+
omitContent: boolean?
332+
path: string
328333
returns:
329334
context: BrowserContext
330335

src/protocol/validator.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
190190
height: tNumber,
191191
})),
192192
})),
193+
recordHar: tOptional(tObject({
194+
omitContent: tOptional(tBoolean),
195+
path: tString,
196+
})),
193197
});
194198
scheme.BrowserCloseParams = tOptional(tObject({}));
195199
scheme.BrowserNewContextParams = tObject({

test/har.spec.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ builder.pageWithHar.init(async ({ contextFactory, testInfo }, run) => {
4646

4747
const { expect, it } = builder.build();
4848

49+
it('should throw without path', async ({ browser }) => {
50+
const error = await browser.newContext({ recordHar: {} as any }).catch(e => e);
51+
expect(error.message).toContain('recordHar.path: expected string, got undefined');
52+
});
53+
4954
it('should have version and creator', async ({ pageWithHar, server }) => {
5055
const { page } = pageWithHar;
5156
await page.goto(server.EMPTY_PAGE);
@@ -78,6 +83,20 @@ it('should have pages', async ({ pageWithHar, server }) => {
7883
expect(pageEntry.pageTimings.onLoad).toBeGreaterThan(0);
7984
});
8085

86+
it('should have pages in persistent context', async ({ launchPersistent, testInfo }) => {
87+
const harPath = testInfo.outputPath('test.har');
88+
const { context, page } = await launchPersistent({ recordHar: { path: harPath } });
89+
await page.goto('data:text/html,<title>Hello</title>');
90+
// For data: load comes before domcontentloaded...
91+
await page.waitForLoadState('domcontentloaded');
92+
await context.close();
93+
const log = JSON.parse(fs.readFileSync(harPath).toString())['log'];
94+
expect(log.pages.length).toBe(1);
95+
const pageEntry = log.pages[0];
96+
expect(pageEntry.id).toBe('page_0');
97+
expect(pageEntry.title).toBe('Hello');
98+
});
99+
81100
it('should include request', async ({ pageWithHar, server }) => {
82101
const { page } = pageWithHar;
83102
await page.goto(server.EMPTY_PAGE);

0 commit comments

Comments
 (0)