diff --git a/docs/src/api/class-browsercontext.md b/docs/src/api/class-browsercontext.md index 57011650a8..54719363e8 100644 --- a/docs/src/api/class-browsercontext.md +++ b/docs/src/api/class-browsercontext.md @@ -1124,17 +1124,17 @@ If specified, updates the given HAR with the actual network information instead A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the pattern will be served from the HAR file. If not specified, all requests are served from the HAR file. -### option: BrowserContext.routeFromHAR.mode +### option: BrowserContext.routeFromHAR.updateMode * since: v1.32 -- `mode` <[HarMode]<"full"|"minimal">> +- `updateMode` <[HarMode]<"full"|"minimal">> When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to `minimal`. -### option: BrowserContext.routeFromHAR.content +### option: BrowserContext.routeFromHAR.updateContent * since: v1.32 -- `content` <[HarContentPolicy]<"omit"|"embed"|"attach">> +- `updateContent` <[RouteFromHarUpdateContentPolicy]<"embed"|"attach">> -Optional setting to control resource content management. If `omit` is specified, content is not persisted. If `attach` is specified, resources are persisted as separate files or entries in the ZIP archive. If `embed` is specified, content is stored inline the HAR file +Optional setting to control resource content management. If `attach` is specified, resources are persisted as separate files or entries in the ZIP archive. If `embed` is specified, content is stored inline the HAR file. ## method: BrowserContext.serviceWorkers * since: v1.11 diff --git a/docs/src/api/class-page.md b/docs/src/api/class-page.md index b06eea2cdf..5e44e58a29 100644 --- a/docs/src/api/class-page.md +++ b/docs/src/api/class-page.md @@ -3335,15 +3335,17 @@ If specified, updates the given HAR with the actual network information instead A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the pattern will be served from the HAR file. If not specified, all requests are served from the HAR file. -### option: Page.routeFromHAR.mode +### option: Page.routeFromHAR.updateMode * since: v1.32 -- `mode` <[HarMode]<"full"|"minimal">> +- `updateMode` <[HarMode]<"full"|"minimal">> + When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to `full`. -### option: Page.routeFromHAR.url +### option: Page.routeFromHAR.updateContent * since: v1.32 -- `content` <[HarContentPolicy]<"omit"|"embed"|"attach">> -Optional setting to control resource content management. If `omit` is specified, content is not persisted. If `attach` is specified, resources are persisted as separate files or entries in the ZIP archive. If `embed` is specified, content is stored inline the HAR file +- `updateContent` <[RouteFromHarUpdateContentPolicy]<"embed"|"attach">> + +Optional setting to control resource content management. If `attach` is specified, resources are persisted as separate files or entries in the ZIP archive. If `embed` is specified, content is stored inline the HAR file. ## async method: Page.screenshot * since: v1.8 diff --git a/packages/playwright-core/src/client/browserContext.ts b/packages/playwright-core/src/client/browserContext.ts index 354dca910f..9851382570 100644 --- a/packages/playwright-core/src/client/browserContext.ts +++ b/packages/playwright-core/src/client/browserContext.ts @@ -266,20 +266,20 @@ export class BrowserContext extends ChannelOwner await this._updateInterceptionPatterns(); } - async _recordIntoHAR(har: string, page: Page | null, options: { url?: string | RegExp, notFound?: 'abort' | 'fallback', update?: boolean, content?: 'omit' | 'attach' | 'embed' | undefined, mode?: 'minimal' | 'full'} = {}): Promise { + async _recordIntoHAR(har: string, page: Page | null, options: { url?: string | RegExp, notFound?: 'abort' | 'fallback', update?: boolean, updateContent?: 'attach' | 'embed', updateMode?: 'minimal' | 'full'} = {}): Promise { const { harId } = await this._channel.harStart({ page: page?._channel, options: prepareRecordHarOptions({ path: har, - content: options.content ?? 'attach', - mode: options.mode ?? 'minimal', + content: options.updateContent ?? 'attach', + mode: options.updateMode ?? 'minimal', urlFilter: options.url })! }); - this._harRecorders.set(harId, { path: har, content: options.content ?? 'attach' }); + this._harRecorders.set(harId, { path: har, content: options.updateContent ?? 'attach' }); } - async routeFromHAR(har: string, options: { url?: string | RegExp, notFound?: 'abort' | 'fallback', update?: boolean, content?: 'omit' | 'attach' | 'embed' | undefined, mode?: 'minimal' | 'full' } = {}): Promise { + async routeFromHAR(har: string, options: { url?: string | RegExp, notFound?: 'abort' | 'fallback', update?: boolean, updateContent?: 'attach' | 'embed', updateMode?: 'minimal' | 'full' } = {}): Promise { if (options.update) { await this._recordIntoHAR(har, null, options); return; diff --git a/packages/playwright-core/src/client/page.ts b/packages/playwright-core/src/client/page.ts index 07fa5286cc..28c9b27ecb 100644 --- a/packages/playwright-core/src/client/page.ts +++ b/packages/playwright-core/src/client/page.ts @@ -458,7 +458,7 @@ export class Page extends ChannelOwner implements api.Page await this._updateInterceptionPatterns(); } - async routeFromHAR(har: string, options: { url?: string | RegExp, notFound?: 'abort' | 'fallback', update?: boolean, content?: 'omit' | 'attach' | 'embed' | undefined, mode?: 'minimal' | 'full'} = {}): Promise { + async routeFromHAR(har: string, options: { url?: string | RegExp, notFound?: 'abort' | 'fallback', update?: boolean, updateContent?: 'attach' | 'embed', updateMode?: 'minimal' | 'full'} = {}): Promise { if (options.update) { await this._browserContext._recordIntoHAR(har, this, options); return; diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts index de0953a54a..1d4f2bb8db 100644 --- a/packages/playwright-core/types/types.d.ts +++ b/packages/playwright-core/types/types.d.ts @@ -3556,10 +3556,6 @@ export interface Page { * @param options */ routeFromHAR(har: string, options?: { - content?: "omit"|"embed"|"attach"; - - mode?: "full"|"minimal"; - /** * - If set to 'abort' any request not found in the HAR file will be aborted. * - If set to 'fallback' missing requests will be sent to the network. @@ -3575,6 +3571,18 @@ export interface Page { */ update?: boolean; + /** + * Optional setting to control resource content management. If `attach` is specified, resources are persisted as + * separate files or entries in the ZIP archive. If `embed` is specified, content is stored inline the HAR file. + */ + updateContent?: "embed"|"attach"; + + /** + * When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, + * cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to `full`. + */ + updateMode?: "full"|"minimal"; + /** * A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the * pattern will be served from the HAR file. If not specified, all requests are served from the HAR file. @@ -8063,20 +8071,6 @@ export interface BrowserContext { * @param options */ routeFromHAR(har: string, options?: { - /** - * Optional setting to control resource content management. If `omit` is specified, content is not persisted. If - * `attach` is specified, resources are persisted as separate files or entries in the ZIP archive. If `embed` is - * specified, content is stored inline the HAR file - */ - content?: "omit"|"embed"|"attach"; - - /** - * When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, - * cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to - * `minimal`. - */ - mode?: "full"|"minimal"; - /** * - If set to 'abort' any request not found in the HAR file will be aborted. * - If set to 'fallback' falls through to the next route handler in the handler chain. @@ -8092,6 +8086,19 @@ export interface BrowserContext { */ update?: boolean; + /** + * Optional setting to control resource content management. If `attach` is specified, resources are persisted as + * separate files or entries in the ZIP archive. If `embed` is specified, content is stored inline the HAR file. + */ + updateContent?: "embed"|"attach"; + + /** + * When set to `minimal`, only record information necessary for routing from HAR. This omits sizes, timing, page, + * cookies, security and other types of HAR information that are not used when replaying from HAR. Defaults to + * `minimal`. + */ + updateMode?: "full"|"minimal"; + /** * A glob pattern, regular expression or predicate to match the request URL. Only requests with URL matching the * pattern will be served from the HAR file. If not specified, all requests are served from the HAR file. diff --git a/tests/library/browsercontext-har.spec.ts b/tests/library/browsercontext-har.spec.ts index 39998b6944..cf56bf97e0 100644 --- a/tests/library/browsercontext-har.spec.ts +++ b/tests/library/browsercontext-har.spec.ts @@ -376,7 +376,7 @@ it('should update har.zip for page with different options', async ({ contextFact const harPath = testInfo.outputPath('har.zip'); const context1 = await contextFactory(); const page1 = await context1.newPage(); - await page1.routeFromHAR(harPath, { 'update': true, 'content': 'embed', 'mode': 'full' }); + await page1.routeFromHAR(harPath, { update: true, updateContent: 'embed', updateMode: 'full' }); await page1.goto(server.PREFIX + '/one-style.html'); await context1.close();