doc(har): add more details into the har doc (#14998)

This commit is contained in:
Pavel Feldman 2022-06-20 17:54:39 -07:00 committed by GitHub
parent bff90b5abb
commit 5e6b493bc9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 31 deletions

View file

@ -250,11 +250,11 @@ state is still returned, but won't be saved to the disk.
## js-context-option-har
* langs: js, python
- `har` <[Object]>
- `path` <[path]> Path to a [HAR](http://www.softwareishard.com/blog/har-12-spec) file with prerecorded network data. If the HAR file contains an entry with the matching URL and HTTP method, then the entry's headers, status and body will be used to fulfill the network request. An entry resulting in a redirect will be followed automatically. If `path` is a relative path, then it is resolved relative to the current working directory.
- `path` <[path]> Path to a [HAR](http://www.softwareishard.com/blog/har-12-spec) file with prerecorded network data. If `path` is a relative path, then it is resolved relative to the current working directory.
- `fallback` ?<[HarFallback]<"abort"|"continue">> If set to 'abort' any request not found in the HAR file will be aborted. If set to'continue' missing requests will be sent to the network. Defaults to 'abort'.
- `urlFilter` ?<[string]|[RegExp]> A glob pattern or regular expression to match request URL while routing. Only requests with URL matching the pattern will be surved from the HAR file. If not specified, all requests are served from the HAR file.
If specified the network requests that are made in the context will be served from the HAR file.
If specified the network requests that are made in the context will be served from the HAR file. Read more about [Replaying from HAR](../network.md#replaying-from-har).
:::note
Playwright will not serve requests intercepted by Service Worker from the HAR file. See [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using request interception. Via `await context.addInitScript(() => delete window.navigator.serviceWorker);`

View file

@ -700,7 +700,7 @@ You can record network activity as an HTTP Archive file (HAR). Later on, this ar
### Recording HAR with CLI
Open the browser with [Playwright CLI](./cli.md) and pass `--save-har` option to produce a HAR file. Optionally, use `--save-har-glob` to only save requests you are interested in, for example API endpoints.
Open the browser with [Playwright CLI](./cli.md) and pass `--save-har` option to produce a HAR file. Optionally, use `--save-har-glob` to only save requests you are interested in, for example API endpoints. If the har file name ends with `.zip`, artifacts are written as separate files and are all compressed into a single `zip`.
```bash js
# Save API requests from example.com as "example.har" archive.
@ -724,7 +724,7 @@ pwsh bin\Debug\netX\playwright.ps1 open --save-har=example.har --save-har-glob="
### Recording HAR with a script
Alternatively, instead of using the CLI, you can record HAR programmatically. Pass [`option: har`] option when creating a [BrowserContext] with [`method: Browser.newContext`] to create an archive.
Alternatively, instead of using the CLI, you can record HAR programmatically. Pass [`option: har`] option when creating a [BrowserContext] with [`method: Browser.newContext`] to create an archive. If the har file name ends with `.zip`, artifacts are written as separate files and are all compressed into a single `zip`.
```js
const context = await browser.newContext({
@ -780,7 +780,7 @@ await context.CloseAsync();
### Replaying from HAR
Pass [`option: har`] option to the [`method: Browser.newContext`] method to use matching responses from the HAR file.
Pass [`option: har`] option to the [`method: Browser.newContext`] method to use matching responses from the [HAR](http://www.softwareishard.com/blog/har-12-spec/) file.
```js
// Replay API requests from HAR.
@ -827,6 +827,10 @@ var page = await context.NewPageAsync();
await page.GotoAsync("https://example.com");
```
HAR replay matches URL and HTTP method strictly. For POST requests, it also matches POST payloads strictly. If multiple recordings match a request, the one with the most matching headers is picked. An entry resulting in a redirect will be followed automatically.
Similar to when recording, if given HAR file name ends with `.zip`, it is considered an archive containing the HAR file along with network payloads stored as separate entries. You can also extract this archive, edit payloads or HAR log manually and point to the extracted har file. All the payloads will be resolved relative to the extracted har file on the file system.
### API reference
- [`method: Browser.newContext`]
- [`method: Route.fulfill`]

View file

@ -10507,7 +10507,8 @@ export interface BrowserType<Unused = {}> {
handleSIGTERM?: boolean;
/**
* If specified the network requests that are made in the context will be served from the HAR file.
* If specified the network requests that are made in the context will be served from the HAR file. Read more about
* [Replaying from HAR](https://playwright.dev/docs/network#replaying-from-har).
*
* > NOTE: Playwright will not serve requests intercepted by Service Worker from the HAR file. See
* [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using
@ -10515,10 +10516,8 @@ export interface BrowserType<Unused = {}> {
*/
har?: {
/**
* Path to a [HAR](http://www.softwareishard.com/blog/har-12-spec) file with prerecorded network data. If the HAR file
* contains an entry with the matching URL and HTTP method, then the entry's headers, status and body will be used to
* fulfill the network request. An entry resulting in a redirect will be followed automatically. If `path` is a relative
* path, then it is resolved relative to the current working directory.
* Path to a [HAR](http://www.softwareishard.com/blog/har-12-spec) file with prerecorded network data. If `path` is a
* relative path, then it is resolved relative to the current working directory.
*/
path: string;
@ -11763,7 +11762,8 @@ export interface AndroidDevice {
};
/**
* If specified the network requests that are made in the context will be served from the HAR file.
* If specified the network requests that are made in the context will be served from the HAR file. Read more about
* [Replaying from HAR](https://playwright.dev/docs/network#replaying-from-har).
*
* > NOTE: Playwright will not serve requests intercepted by Service Worker from the HAR file. See
* [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using
@ -11771,10 +11771,8 @@ export interface AndroidDevice {
*/
har?: {
/**
* Path to a [HAR](http://www.softwareishard.com/blog/har-12-spec) file with prerecorded network data. If the HAR file
* contains an entry with the matching URL and HTTP method, then the entry's headers, status and body will be used to
* fulfill the network request. An entry resulting in a redirect will be followed automatically. If `path` is a relative
* path, then it is resolved relative to the current working directory.
* Path to a [HAR](http://www.softwareishard.com/blog/har-12-spec) file with prerecorded network data. If `path` is a
* relative path, then it is resolved relative to the current working directory.
*/
path: string;
@ -13332,7 +13330,8 @@ export interface Browser extends EventEmitter {
};
/**
* If specified the network requests that are made in the context will be served from the HAR file.
* If specified the network requests that are made in the context will be served from the HAR file. Read more about
* [Replaying from HAR](https://playwright.dev/docs/network#replaying-from-har).
*
* > NOTE: Playwright will not serve requests intercepted by Service Worker from the HAR file. See
* [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using
@ -13340,10 +13339,8 @@ export interface Browser extends EventEmitter {
*/
har?: {
/**
* Path to a [HAR](http://www.softwareishard.com/blog/har-12-spec) file with prerecorded network data. If the HAR file
* contains an entry with the matching URL and HTTP method, then the entry's headers, status and body will be used to
* fulfill the network request. An entry resulting in a redirect will be followed automatically. If `path` is a relative
* path, then it is resolved relative to the current working directory.
* Path to a [HAR](http://www.softwareishard.com/blog/har-12-spec) file with prerecorded network data. If `path` is a
* relative path, then it is resolved relative to the current working directory.
*/
path: string;
@ -14205,7 +14202,8 @@ export interface Electron {
};
/**
* If specified the network requests that are made in the context will be served from the HAR file.
* If specified the network requests that are made in the context will be served from the HAR file. Read more about
* [Replaying from HAR](https://playwright.dev/docs/network#replaying-from-har).
*
* > NOTE: Playwright will not serve requests intercepted by Service Worker from the HAR file. See
* [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using
@ -14213,10 +14211,8 @@ export interface Electron {
*/
har?: {
/**
* Path to a [HAR](http://www.softwareishard.com/blog/har-12-spec) file with prerecorded network data. If the HAR file
* contains an entry with the matching URL and HTTP method, then the entry's headers, status and body will be used to
* fulfill the network request. An entry resulting in a redirect will be followed automatically. If `path` is a relative
* path, then it is resolved relative to the current working directory.
* Path to a [HAR](http://www.softwareishard.com/blog/har-12-spec) file with prerecorded network data. If `path` is a
* relative path, then it is resolved relative to the current working directory.
*/
path: string;
@ -15999,7 +15995,8 @@ export interface BrowserContextOptions {
geolocation?: Geolocation;
/**
* If specified the network requests that are made in the context will be served from the HAR file.
* If specified the network requests that are made in the context will be served from the HAR file. Read more about
* [Replaying from HAR](https://playwright.dev/docs/network#replaying-from-har).
*
* > NOTE: Playwright will not serve requests intercepted by Service Worker from the HAR file. See
* [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using
@ -16007,10 +16004,8 @@ export interface BrowserContextOptions {
*/
har?: {
/**
* Path to a [HAR](http://www.softwareishard.com/blog/har-12-spec) file with prerecorded network data. If the HAR file
* contains an entry with the matching URL and HTTP method, then the entry's headers, status and body will be used to
* fulfill the network request. An entry resulting in a redirect will be followed automatically. If `path` is a relative
* path, then it is resolved relative to the current working directory.
* Path to a [HAR](http://www.softwareishard.com/blog/har-12-spec) file with prerecorded network data. If `path` is a
* relative path, then it is resolved relative to the current working directory.
*/
path: string;

View file

@ -2701,7 +2701,8 @@ export interface PlaywrightTestOptions {
extraHTTPHeaders: ExtraHTTPHeaders | undefined;
geolocation: Geolocation | undefined;
/**
* If specified the network requests that are made in the context will be served from the HAR file.
* If specified the network requests that are made in the context will be served from the HAR file. Read more about
* [Replaying from HAR](https://playwright.dev/docs/network#replaying-from-har).
*
* > NOTE: Playwright will not serve requests intercepted by Service Worker from the HAR file. See
* [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using