docs: update network guide to use routeFromHar (#14887)
This commit is contained in:
parent
df63ae9dce
commit
a422c77f2b
|
|
@ -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 page.routeFromHar('example.har', { url: '**/api/**' });
|
||||||
await route.fulfill({ har: { path: 'example.har' } });
|
|
||||||
});
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```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.
|
page.routeFromHar(Paths.get("example.har"), new Page.RouteFromHarOptions().setUrl("**/api/**"));
|
||||||
route.fulfill(new Route.FulfillOptions().setHarPath(Paths.get("example.har")));
|
|
||||||
});
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```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 page.route_from_har("example.har", url="**/api/**")
|
||||||
await route.fulfill(har_path="example.har")
|
|
||||||
|
|
||||||
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.
|
page.route_from_har("example.har", url="**/api/**")
|
||||||
route.fulfill(har_path="example.har")
|
|
||||||
|
|
||||||
page.route("**/api/**", handle_route)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
await Page.RouteAsync("**/api/**", async route =>
|
// Either use a matching response from the HAR,
|
||||||
{
|
// or abort the request if nothing matches.
|
||||||
// Either use a matching response from the HAR,
|
await Page.RouteFromHarAsync("example.har", new () { Url = "**/api/**" });
|
||||||
// or abort the request if nothing matches.
|
|
||||||
await route.FulfillAsync(new()
|
|
||||||
{
|
|
||||||
HarPath = "example.har",
|
|
||||||
});
|
|
||||||
});
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### API reference
|
### API reference
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue