docs: update route.fetch example to use new api (#20040)

This commit is contained in:
Yury Semikhatsky 2023-01-11 09:15:21 -08:00 committed by GitHub
parent 2394debce5
commit 0206d5fb18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -575,7 +575,7 @@ To modify a response use [APIRequestContext] to get the original response and th
```js ```js
await page.route('**/title.html', async route => { await page.route('**/title.html', async route => {
// Fetch original response. // Fetch original response.
const response = await page.request.fetch(route.request()); const response = await route.fetch();
// Add a prefix to the title. // Add a prefix to the title.
let body = await response.text(); let body = await response.text();
body = body.replace('<title>', '<title>My prefix:'); body = body.replace('<title>', '<title>My prefix:');
@ -596,7 +596,7 @@ await page.route('**/title.html', async route => {
```java ```java
page.route("**/title.html", route -> { page.route("**/title.html", route -> {
// Fetch original response. // Fetch original response.
APIResponse response = page.request().fetch(route.request()); APIResponse response = route.fetch();
// Add a prefix to the title. // Add a prefix to the title.
String body = response.text(); String body = response.text();
body = body.replace("<title>", "<title>My prefix:"); body = body.replace("<title>", "<title>My prefix:");
@ -615,7 +615,7 @@ page.route("**/title.html", route -> {
```python async ```python async
async def handle_route(route: Route) -> None: async def handle_route(route: Route) -> None:
# Fetch original response. # Fetch original response.
response = await page.request.fetch(route.request) response = await route.fetch()
# Add a prefix to the title. # Add a prefix to the title.
body = await response.text() body = await response.text()
body = body.replace("<title>", "<title>My prefix:") body = body.replace("<title>", "<title>My prefix:")
@ -634,7 +634,7 @@ await page.route("**/title.html", handle_route)
```python sync ```python sync
def handle_route(route: Route) -> None: def handle_route(route: Route) -> None:
# Fetch original response. # Fetch original response.
response = page.request.fetch(route.request) response = route.fetch()
# Add a prefix to the title. # Add a prefix to the title.
body = response.text() body = response.text()
body = body.replace("<title>", "<title>My prefix:") body = body.replace("<title>", "<title>My prefix:")
@ -654,7 +654,7 @@ page.route("**/title.html", handle_route)
await Page.RouteAsync("**/title.html", async route => await Page.RouteAsync("**/title.html", async route =>
{ {
// Fetch original response. // Fetch original response.
var response = await Page.APIRequest.FetchAsync(route.Request); var response = await route.FetchAsync();
// Add a prefix to the title. // Add a prefix to the title.
var body = await response.TextAsync(); var body = await response.TextAsync();
body = body.Replace("<title>", "<title>My prefix:"); body = body.Replace("<title>", "<title>My prefix:");