diff --git a/docs/src/api-testing-js.md b/docs/src/api-testing-js.md index 03e0e6dfcc..680b085a3c 100644 --- a/docs/src/api-testing-js.md +++ b/docs/src/api-testing-js.md @@ -331,7 +331,7 @@ test('context request will share cookie storage with its browser context', async [name, value]) )).toEqual(responseCookies); - route.fulfill({ + await route.fulfill({ response, headers: { ...responseHeaders, foo: 'bar' }, }); @@ -375,7 +375,7 @@ test('global context request has isolated cookie storage', async ({ new Map(contextCookies2.map(({ name, value }) => [name, value])) ).toEqual(responseCookies); - route.fulfill({ + await route.fulfill({ response, headers: { ...responseHeaders, foo: 'bar' }, }); diff --git a/docs/src/api/class-browsercontext.md b/docs/src/api/class-browsercontext.md index e414e0e89d..87f6369b5c 100644 --- a/docs/src/api/class-browsercontext.md +++ b/docs/src/api/class-browsercontext.md @@ -1120,11 +1120,11 @@ await browser.CloseAsync(); It is possible to examine the request to decide the route action. For example, mocking all requests that contain some post data, and leaving all other requests as is: ```js -await context.route('/api/**', route => { +await context.route('/api/**', async route => { if (route.request().postData().includes('my-string')) - route.fulfill({ body: 'mocked-data' }); + await route.fulfill({ body: 'mocked-data' }); else - route.continue(); + await route.continue(); }); ``` @@ -1138,16 +1138,16 @@ context.route("/api/**", route -> { ``` ```python async -def handle_route(route): +async def handle_route(route: Route): if ("my-string" in route.request.post_data): - route.fulfill(body="mocked-data") + await route.fulfill(body="mocked-data") else: - route.continue_() + await route.continue_() await context.route("/api/**", handle_route) ``` ```python sync -def handle_route(route): +def handle_route(route: Route): if ("my-string" in route.request.post_data): route.fulfill(body="mocked-data") else: diff --git a/docs/src/api/class-page.md b/docs/src/api/class-page.md index f6c6e84a69..2923eb8ba9 100644 --- a/docs/src/api/class-page.md +++ b/docs/src/api/class-page.md @@ -3456,11 +3456,11 @@ await page.GotoAsync("https://www.microsoft.com"); It is possible to examine the request to decide the route action. For example, mocking all requests that contain some post data, and leaving all other requests as is: ```js -await page.route('/api/**', route => { +await page.route('/api/**', async route => { if (route.request().postData().includes('my-string')) - route.fulfill({ body: 'mocked-data' }); + await route.fulfill({ body: 'mocked-data' }); else - route.continue(); + await route.continue(); }); ``` @@ -3474,16 +3474,16 @@ page.route("/api/**", route -> { ``` ```python async -def handle_route(route): +async def handle_route(route: Route): if ("my-string" in route.request.post_data): - route.fulfill(body="mocked-data") + await route.fulfill(body="mocked-data") else: - route.continue_() + await route.continue_() await page.route("/api/**", handle_route) ``` ```python sync -def handle_route(route): +def handle_route(route: Route): if ("my-string" in route.request.post_data): route.fulfill(body="mocked-data") else: diff --git a/docs/src/api/class-route.md b/docs/src/api/class-route.md index f55843ef5d..dcdca4705a 100644 --- a/docs/src/api/class-route.md +++ b/docs/src/api/class-route.md @@ -92,11 +92,11 @@ page.route("**/*", handle) ``` ```csharp -await page.RouteAsync("**/*", route => +await page.RouteAsync("**/*", async route => { var headers = new Dictionary(route.Request.Headers) { { "foo", "bar" } }; headers.Remove("origin"); - route.ContinueAsync(headers); + await route.ContinueAsync(new() { Headers = headers }); }); ``` @@ -264,17 +264,17 @@ page.route("**/*", route -> { ```python async # Handle GET requests. -def handle_get(route): +async def handle_get(route): if route.request.method != "GET": - route.fallback() + await route.fallback() return # Handling GET only. # ... # Handle POST requests. -def handle_post(route): +async def handle_post(route): if route.request.method != "POST": - route.fallback() + await route.fallback() return # Handling POST only. # ... @@ -378,11 +378,11 @@ page.route("**/*", handle) ``` ```csharp -await page.RouteAsync("**/*", route => +await page.RouteAsync("**/*", async route => { var headers = new Dictionary(route.Request.Headers) { { "foo", "foo-value" } }; headers.Remove("bar"); - route.FallbackAsync(headers); + await route.FallbackAsync(new() { Headers = headers }); }); ``` diff --git a/docs/src/network.md b/docs/src/network.md index 9f1a5b2cf2..438e929e0c 100644 --- a/docs/src/network.md +++ b/docs/src/network.md @@ -495,10 +495,10 @@ await page.GotoAsync("https://example.com"); ```js // Delete header -await page.route('**/*', route => { +await page.route('**/*', async route => { const headers = route.request().headers(); delete headers['X-Secret']; - route.continue({ headers }); + await route.continue({ headers }); }); // Continue requests as POST. @@ -522,7 +522,7 @@ page.route("**/*", route -> route.resume(new Route.ResumeOptions().setMethod("PO async def handle_route(route): headers = route.request.headers del headers["x-secret"] - route.continue_(headers=headers) + await route.continue_(headers=headers) await page.route("**/*", handle_route) # Continue requests as POST. @@ -617,7 +617,7 @@ await page.route('**/title.html', async route => { // Add a prefix to the title. let body = await response.text(); body = body.replace('', '<title>My prefix:'); - route.fulfill({ + await route.fulfill({ // Pass all fields from the response. response, // Override response body. diff --git a/docs/src/release-notes-js.md b/docs/src/release-notes-js.md index 2abf68f12c..c496c20ffd 100644 --- a/docs/src/release-notes-js.md +++ b/docs/src/release-notes-js.md @@ -1233,16 +1233,16 @@ test.beforeEach(async ({ page }) => { await page.route('**/*', async route => { const headers = await route.request().allHeaders(); delete headers['if-none-match']; - route.fallback({ headers }); + await route.fallback({ headers }); }); }); test('should work', async ({ page }) => { - await page.route('**/*', route => { + await page.route('**/*', async route => { if (route.request().resourceType() === 'image') - route.abort(); + await route.abort(); else - route.fallback(); + await route.fallback(); }); }); ``` @@ -1813,7 +1813,7 @@ test('response interception', async ({ page }) => { const response = await page._request.fetch(route.request()); const image = await jimp.read(await response.body()); await image.blur(5); - route.fulfill({ + await route.fulfill({ response, body: await image.getBufferAsync('image/jpeg'), }); diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts index f53b1d9ff4..80bb5c52bb 100644 --- a/packages/playwright-core/types/types.d.ts +++ b/packages/playwright-core/types/types.d.ts @@ -3665,11 +3665,11 @@ export interface Page { * some post data, and leaving all other requests as is: * * ```js - * await page.route('/api/**', route => { + * await page.route('/api/**', async route => { * if (route.request().postData().includes('my-string')) - * route.fulfill({ body: 'mocked-data' }); + * await route.fulfill({ body: 'mocked-data' }); * else - * route.continue(); + * await route.continue(); * }); * ``` * @@ -8464,11 +8464,11 @@ export interface BrowserContext { * some post data, and leaving all other requests as is: * * ```js - * await context.route('/api/**', route => { + * await context.route('/api/**', async route => { * if (route.request().postData().includes('my-string')) - * route.fulfill({ body: 'mocked-data' }); + * await route.fulfill({ body: 'mocked-data' }); * else - * route.continue(); + * await route.continue(); * }); * ``` *