feat(routeFromHAR): add arguments (#21223)
This commit is contained in:
parent
e28801f6ef
commit
e17e0e40f8
|
|
@ -1124,6 +1124,18 @@ 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
|
||||
* since: v1.32
|
||||
- `mode` <[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
|
||||
* 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
|
||||
|
||||
## method: BrowserContext.serviceWorkers
|
||||
* since: v1.11
|
||||
* langs: js, python
|
||||
|
|
|
|||
|
|
@ -3272,6 +3272,16 @@ 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
|
||||
* since: v1.32
|
||||
- `mode` <[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
|
||||
* 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
|
||||
|
||||
## async method: Page.screenshot
|
||||
* since: v1.8
|
||||
- returns: <[Buffer]>
|
||||
|
|
|
|||
|
|
@ -265,20 +265,20 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel>
|
|||
await this._updateInterceptionPatterns();
|
||||
}
|
||||
|
||||
async _recordIntoHAR(har: string, page: Page | null, options: { url?: string | RegExp, notFound?: 'abort' | 'fallback', update?: boolean } = {}): Promise<void> {
|
||||
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<void> {
|
||||
const { harId } = await this._channel.harStart({
|
||||
page: page?._channel,
|
||||
options: prepareRecordHarOptions({
|
||||
path: har,
|
||||
content: 'attach',
|
||||
mode: 'minimal',
|
||||
content: options.content ?? 'attach',
|
||||
mode: options.mode ?? 'minimal',
|
||||
urlFilter: options.url
|
||||
})!
|
||||
});
|
||||
this._harRecorders.set(harId, { path: har, content: 'attach' });
|
||||
this._harRecorders.set(harId, { path: har, content: options.content ?? 'attach' });
|
||||
}
|
||||
|
||||
async routeFromHAR(har: string, options: { url?: string | RegExp, notFound?: 'abort' | 'fallback', update?: boolean } = {}): Promise<void> {
|
||||
async routeFromHAR(har: string, options: { url?: string | RegExp, notFound?: 'abort' | 'fallback', update?: boolean, content?: 'omit' | 'attach' | 'embed' | undefined, mode?: 'minimal' | 'full' } = {}): Promise<void> {
|
||||
if (options.update) {
|
||||
await this._recordIntoHAR(har, null, options);
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -460,7 +460,7 @@ export class Page extends ChannelOwner<channels.PageChannel> implements api.Page
|
|||
await this._updateInterceptionPatterns();
|
||||
}
|
||||
|
||||
async routeFromHAR(har: string, options: { url?: string | RegExp, notFound?: 'abort' | 'fallback', update?: boolean } = {}): Promise<void> {
|
||||
async routeFromHAR(har: string, options: { url?: string | RegExp, notFound?: 'abort' | 'fallback', update?: boolean, content?: 'omit' | 'attach' | 'embed' | undefined, mode?: 'minimal' | 'full'} = {}): Promise<void> {
|
||||
if (options.update) {
|
||||
await this._browserContext._recordIntoHAR(har, this, options);
|
||||
return;
|
||||
|
|
|
|||
18
packages/playwright-core/types/types.d.ts
vendored
18
packages/playwright-core/types/types.d.ts
vendored
|
|
@ -3556,6 +3556,10 @@ 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.
|
||||
|
|
@ -8057,6 +8061,20 @@ 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.
|
||||
|
|
|
|||
|
|
@ -371,6 +371,23 @@ it('should update har.zip for page', async ({ contextFactory, server }, testInfo
|
|||
await expect(page2.locator('body')).toHaveCSS('background-color', 'rgb(255, 192, 203)');
|
||||
});
|
||||
|
||||
|
||||
it('should update har.zip for page with different options', async ({ contextFactory, server }, testInfo) => {
|
||||
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.goto(server.PREFIX + '/one-style.html');
|
||||
await context1.close();
|
||||
|
||||
const context2 = await contextFactory();
|
||||
const page2 = await context2.newPage();
|
||||
await page2.routeFromHAR(harPath, { notFound: 'abort' });
|
||||
await page2.goto(server.PREFIX + '/one-style.html');
|
||||
expect(await page2.content()).toContain('hello, world!');
|
||||
await expect(page2.locator('body')).toHaveCSS('background-color', 'rgb(255, 192, 203)');
|
||||
});
|
||||
|
||||
it('should update extracted har.zip for page', async ({ contextFactory, server }, testInfo) => {
|
||||
const harPath = testInfo.outputPath('har.har');
|
||||
const context1 = await contextFactory();
|
||||
|
|
|
|||
Loading…
Reference in a new issue