From 0f8114f6a80a093b80921821656eff6053a25b9a Mon Sep 17 00:00:00 2001 From: Ross Wollman Date: Mon, 20 Jun 2022 19:31:19 -0700 Subject: [PATCH] docs: replace serviceWorkers workaround (#14902) --- docs/src/api/class-browsercontext.md | 2 +- docs/src/api/class-page.md | 2 +- docs/src/api/params.md | 2 +- packages/playwright-core/types/types.d.ts | 23 ++++++++++++----------- packages/playwright-test/types/test.d.ts | 2 +- 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/docs/src/api/class-browsercontext.md b/docs/src/api/class-browsercontext.md index 7a778d2f68..0d9b885896 100644 --- a/docs/src/api/class-browsercontext.md +++ b/docs/src/api/class-browsercontext.md @@ -854,7 +854,7 @@ Routing provides the capability to modify network requests that are made by any is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted. :::note -[`method: Page.route`] will not intercept requests intercepted by Service Worker. 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);` +[`method: BrowserContext.route`] will not intercept requests intercepted by Service Worker. See [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using request interception by setting [`option: Browser.newContext.serviceWorkers`] to `'block'`. ::: An example of a naive handler that aborts all image requests: diff --git a/docs/src/api/class-page.md b/docs/src/api/class-page.md index 77e3568806..3d7ce62369 100644 --- a/docs/src/api/class-page.md +++ b/docs/src/api/class-page.md @@ -2577,7 +2577,7 @@ The handler will only be called for the first url if the response is a redirect. ::: :::note -[`method: Page.route`] will not intercept requests intercepted by Service Worker. 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);` +[`method: Page.route`] will not intercept requests intercepted by Service Worker. See [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using request interception by setting [`option: Browser.newContext.serviceWorkers`] to `'block'`. ::: An example of a naive handler that aborts all image requests: diff --git a/docs/src/api/params.md b/docs/src/api/params.md index 90e6235d1a..d31b67a55e 100644 --- a/docs/src/api/params.md +++ b/docs/src/api/params.md @@ -257,7 +257,7 @@ state is still returned, but won't be saved to the disk. 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);` +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 by setting [`option: Browser.newContext.serviceWorkers`] to `'block'`. ::: ## csharp-java-python-context-option-har-path diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts index c73d42750c..50973d37d0 100644 --- a/packages/playwright-core/types/types.d.ts +++ b/packages/playwright-core/types/types.d.ts @@ -3114,8 +3114,8 @@ export interface Page { * > NOTE: The handler will only be called for the first url if the response is a redirect. * > NOTE: [page.route(url, handler[, options])](https://playwright.dev/docs/api/class-page#page-route) will not intercept * requests intercepted by Service Worker. 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);` + * recommend disabling Service Workers when using request interception by setting `Browser.newContext.serviceWorkers` to + * `'block'`. * * An example of a naive handler that aborts all image requests: * @@ -7036,10 +7036,11 @@ export interface BrowserContext { * Routing provides the capability to modify network requests that are made by any page in the browser context. Once route * is enabled, every request matching the url pattern will stall unless it's continued, fulfilled or aborted. * - * > NOTE: [page.route(url, handler[, options])](https://playwright.dev/docs/api/class-page#page-route) will not intercept - * requests intercepted by Service Worker. 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);` + * > NOTE: + * [browserContext.route(url, handler[, options])](https://playwright.dev/docs/api/class-browsercontext#browser-context-route) + * will not intercept requests intercepted by Service Worker. See + * [this](https://github.com/microsoft/playwright/issues/1090) issue. We recommend disabling Service Workers when using + * request interception by setting `Browser.newContext.serviceWorkers` to `'block'`. * * An example of a naive handler that aborts all image requests: * @@ -10512,7 +10513,7 @@ export interface BrowserType { * * > 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);` + * request interception by setting `Browser.newContext.serviceWorkers` to `'block'`. */ har?: { /** @@ -11767,7 +11768,7 @@ export interface AndroidDevice { * * > 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);` + * request interception by setting `Browser.newContext.serviceWorkers` to `'block'`. */ har?: { /** @@ -13335,7 +13336,7 @@ export interface Browser extends EventEmitter { * * > 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);` + * request interception by setting `Browser.newContext.serviceWorkers` to `'block'`. */ har?: { /** @@ -14207,7 +14208,7 @@ export interface Electron { * * > 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);` + * request interception by setting `Browser.newContext.serviceWorkers` to `'block'`. */ har?: { /** @@ -16000,7 +16001,7 @@ export interface BrowserContextOptions { * * > 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);` + * request interception by setting `Browser.newContext.serviceWorkers` to `'block'`. */ har?: { /** diff --git a/packages/playwright-test/types/test.d.ts b/packages/playwright-test/types/test.d.ts index f79a13d9f1..aed32d9956 100644 --- a/packages/playwright-test/types/test.d.ts +++ b/packages/playwright-test/types/test.d.ts @@ -2706,7 +2706,7 @@ export interface PlaywrightTestOptions { * * > 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);` + * request interception by setting `Browser.newContext.serviceWorkers` to `'block'`. */ har: HAROptions | undefined; /**