docs: update network guide to use routeFromHar (#14887)

This commit is contained in:
Yury Semikhatsky 2022-06-15 09:33:19 -07:00 committed by GitHub
parent df63ae9dce
commit a422c77f2b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -784,49 +784,33 @@ Pass [`option: har`] option to the [`method: Route.fulfill`] method to use a mat
```js ```js
// Replay API requests from HAR. // Replay API requests from HAR.
await page.route('**/api/**', async route => {
// Either use a matching response from the HAR, // Either use a matching response from the HAR,
// or abort the request if nothing matches. // or abort the request if nothing matches.
await route.fulfill({ har: { path: 'example.har' } }); await page.routeFromHar('example.har', { url: '**/api/**' });
});
``` ```
```java ```java
page.route("**/api/**", route -> {
// Either use a matching response from the HAR, // Either use a matching response from the HAR,
// or abort the request if nothing matches. // or abort the request if nothing matches.
route.fulfill(new Route.FulfillOptions().setHarPath(Paths.get("example.har"))); page.routeFromHar(Paths.get("example.har"), new Page.RouteFromHarOptions().setUrl("**/api/**"));
});
``` ```
```python async ```python async
async def handle_route(route: Route) -> None:
# Either use a matching response from the HAR, # Either use a matching response from the HAR,
# or abort the request if nothing matches. # or abort the request if nothing matches.
await route.fulfill(har_path="example.har") await page.route_from_har("example.har", url="**/api/**")
await page.route("**/api/**", handle_route)
``` ```
```python sync ```python sync
def handle_route(route: Route) -> None:
# Either use a matching response from the HAR, # Either use a matching response from the HAR,
# or abort the request if nothing matches. # or abort the request if nothing matches.
route.fulfill(har_path="example.har") page.route_from_har("example.har", url="**/api/**")
page.route("**/api/**", handle_route)
``` ```
```csharp ```csharp
await Page.RouteAsync("**/api/**", async route =>
{
// Either use a matching response from the HAR, // Either use a matching response from the HAR,
// or abort the request if nothing matches. // or abort the request if nothing matches.
await route.FulfillAsync(new() await Page.RouteFromHarAsync("example.har", new () { Url = "**/api/**" });
{
HarPath = "example.har",
});
});
``` ```
### API reference ### API reference