From c5047529337d39d90742802c7e3346c0d5b68407 Mon Sep 17 00:00:00 2001 From: "microsoft-playwright-automation[bot]" <203992400+microsoft-playwright-automation[bot]@users.noreply.github.com> Date: Fri, 5 Dec 2025 10:10:05 +0000 Subject: [PATCH] feat(roll): roll to ToT Playwright (05-12-25) --- dotnet/docs/api/class-browsertype.mdx | 20 +- dotnet/docs/ci.mdx | 10 +- dotnet/docs/docker.mdx | 16 +- dotnet/docs/release-notes.mdx | 28 +++ java/docs/api/class-browsertype.mdx | 20 +- java/docs/ci.mdx | 12 +- java/docs/docker.mdx | 16 +- java/docs/intro.mdx | 2 +- java/docs/locators.mdx | 4 +- java/docs/release-notes.mdx | 28 +++ java/docs/test-runners.mdx | 4 +- nodejs/docs/api/class-browsertype.mdx | 30 +-- nodejs/docs/api/class-consolemessage.mdx | 2 +- nodejs/docs/api/class-testoptions.mdx | 2 +- nodejs/docs/release-notes.mdx | 4 +- python/docs/api/class-browsertype.mdx | 20 +- python/docs/api/class-consolemessage.mdx | 2 +- python/docs/api/class-request.mdx | 23 ++ python/docs/release-notes.mdx | 30 +++ python/docs/service-workers.mdx | 262 +++++++++++++++++++++++ 20 files changed, 417 insertions(+), 118 deletions(-) create mode 100644 python/docs/service-workers.mdx diff --git a/dotnet/docs/api/class-browsertype.mdx b/dotnet/docs/api/class-browsertype.mdx index f6f48e227a8..d44e785d438 100644 --- a/dotnet/docs/api/class-browsertype.mdx +++ b/dotnet/docs/api/class-browsertype.mdx @@ -187,14 +187,6 @@ var browser = await playwright.Chromium.LaunchAsync(new() { - `ChromiumSandbox` [bool]? *(optional)*# Enable Chromium sandboxing. Defaults to `false`. - - `Devtools` [bool]? *(optional)*# - - :::warning[Deprecated] - Use [debugging tools](../debug.mdx) instead. - ::: - - - **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the [Headless](/api/class-browsertype.mdx#browser-type-launch-option-headless) option will be set `false`. - `DownloadsPath` [string]? *(optional)*# If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is deleted when browser is closed. In either case, the downloads are deleted when the browser context they were created in is closed. @@ -220,7 +212,7 @@ var browser = await playwright.Chromium.LaunchAsync(new() { Close the browser process on SIGTERM. Defaults to `true`. - `Headless` [bool]? *(optional)*# - Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/). Defaults to `true` unless the [Devtools](/api/class-browsertype.mdx#browser-type-launch-option-devtools) option is `true`. + Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/). Defaults to `true`. - `IgnoreAllDefaultArgs` [bool]? *(optional)* Added in: v1.9# If `true`, Playwright does not pass its own configurations args and only uses the ones from [Args](/api/class-browsertype.mdx#browser-type-launch-option-args). Dangerous option; use with care. Defaults to `false`. @@ -364,14 +356,6 @@ await BrowserType.LaunchPersistentContextAsync(userDataDir, options); - `DeviceScaleFactor` [float]? *(optional)*# Specify device scale factor (can be thought of as dpr). Defaults to `1`. Learn more about [emulating devices with device scale factor](../emulation.mdx#devices). - - `Devtools` [bool]? *(optional)*# - - :::warning[Deprecated] - Use [debugging tools](../debug.mdx) instead. - ::: - - - **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the [Headless](/api/class-browsertype.mdx#browser-type-launch-persistent-context-option-headless) option will be set `false`. - `DownloadsPath` [string]? *(optional)*# If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is deleted when browser is closed. In either case, the downloads are deleted when the browser context they were created in is closed. @@ -416,7 +400,7 @@ await BrowserType.LaunchPersistentContextAsync(userDataDir, options); Specifies if viewport supports touch events. Defaults to false. Learn more about [mobile emulation](../emulation.mdx#devices). - `Headless` [bool]? *(optional)*# - Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/). Defaults to `true` unless the [Devtools](/api/class-browsertype.mdx#browser-type-launch-option-devtools) option is `true`. + Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/). Defaults to `true`. - `HttpCredentials` HttpCredentials? *(optional)*# - `Username` [string] diff --git a/dotnet/docs/ci.mdx b/dotnet/docs/ci.mdx index d0df1c2cc2d..cf201dd8bed 100644 --- a/dotnet/docs/ci.mdx +++ b/dotnet/docs/ci.mdx @@ -76,7 +76,7 @@ jobs: name: 'Playwright Tests' runs-on: ubuntu-latest container: - image: mcr.microsoft.com/playwright/dotnet:v1.56.0-noble + image: mcr.microsoft.com/playwright/dotnet:v1.57.0-noble options: --user 1001 steps: - uses: actions/checkout@v5 @@ -159,7 +159,7 @@ trigger: pool: vmImage: ubuntu-latest -container: mcr.microsoft.com/playwright/dotnet:v1.56.0-noble +container: mcr.microsoft.com/playwright/dotnet:v1.57.0-noble steps: - task: UseDotNet@2 @@ -182,7 +182,7 @@ Running Playwright on CircleCI is very similar to running on GitHub Actions. In executors: pw-noble-development: docker: - - image: mcr.microsoft.com/playwright/dotnet:v1.56.0-noble + - image: mcr.microsoft.com/playwright/dotnet:v1.57.0-noble ``` Note: When using the docker agent definition, you are specifying the resource class of where playwright runs to the 'medium' tier [here](https://circleci.com/docs/configuration-reference?#docker-execution-environment). The default behavior of Playwright is to set the number of workers to the detected core count (2 in the case of the medium tier). Overriding the number of workers to greater than this number will cause unnecessary timeouts and failures. @@ -193,7 +193,7 @@ Jenkins supports Docker agents for pipelines. Use the [Playwright Docker image]( ```groovy pipeline { - agent { docker { image 'mcr.microsoft.com/playwright/dotnet:v1.56.0-noble' } } + agent { docker { image 'mcr.microsoft.com/playwright/dotnet:v1.57.0-noble' } } stages { stage('e2e-tests') { steps { @@ -210,7 +210,7 @@ pipeline { Bitbucket Pipelines can use public [Docker images as build environments](https://confluence.atlassian.com/bitbucket/use-docker-images-as-build-environments-792298897.html). To run Playwright tests on Bitbucket, use our public Docker image ([see Dockerfile](./docker.mdx)). ```yml -image: mcr.microsoft.com/playwright/dotnet:v1.56.0-noble +image: mcr.microsoft.com/playwright/dotnet:v1.57.0-noble ``` ### GitLab CI diff --git a/dotnet/docs/docker.mdx b/dotnet/docs/docker.mdx index db075a24a36..90dd50511aa 100644 --- a/dotnet/docs/docker.mdx +++ b/dotnet/docs/docker.mdx @@ -22,7 +22,7 @@ This Docker image is intended to be used for testing and development purposes on ### Pull the image ```bash -docker pull mcr.microsoft.com/playwright/dotnet:v1.56.0-noble +docker pull mcr.microsoft.com/playwright/dotnet:v1.57.0-noble ``` ### Run the image @@ -34,7 +34,7 @@ By default, the Docker image will use the `root` user to run the browsers. This On trusted websites, you can avoid creating a separate user and use root for it since you trust the code which will run on the browsers. ```bash -docker run -it --rm --ipc=host mcr.microsoft.com/playwright/dotnet:v1.56.0-noble /bin/bash +docker run -it --rm --ipc=host mcr.microsoft.com/playwright/dotnet:v1.57.0-noble /bin/bash ``` #### Crawling and scraping @@ -42,7 +42,7 @@ docker run -it --rm --ipc=host mcr.microsoft.com/playwright/dotnet:v1.56.0-noble On untrusted websites, it's recommended to use a separate user for launching the browsers in combination with the seccomp profile. Inside the container or if you are using the Docker image as a base image you have to use `adduser` for it. ```bash -docker run -it --rm --ipc=host --user pwuser --security-opt seccomp=seccomp_profile.json mcr.microsoft.com/playwright/dotnet:v1.56.0-noble /bin/bash +docker run -it --rm --ipc=host --user pwuser --security-opt seccomp=seccomp_profile.json mcr.microsoft.com/playwright/dotnet:v1.57.0-noble /bin/bash ``` [`seccomp_profile.json`](https://github.com/microsoft/playwright/blob/main/utils/docker/seccomp_profile.json) is needed to run Chromium with sandbox. This is a [default Docker seccomp profile](https://github.com/docker/engine/blob/d0d99b04cf6e00ed3fc27e81fc3d94e7eda70af3/profiles/seccomp/default.json) with extra user namespace cloning permissions: @@ -82,7 +82,7 @@ You can run Playwright Server in Docker while keeping your tests running on the Start the Playwright Server in Docker: ```bash -docker run -p 3000:3000 --rm --init -it --workdir /home/pwuser --user pwuser mcr.microsoft.com/playwright:v1.56.0-noble /bin/sh -c "npx -y playwright@1.56.0 run-server --port 3000 --host 0.0.0.0" +docker run -p 3000:3000 --rm --init -it --workdir /home/pwuser --user pwuser mcr.microsoft.com/playwright:v1.57.0-noble /bin/sh -c "npx -y playwright@1.57.0 run-server --port 3000 --host 0.0.0.0" ``` #### Connecting to the Server @@ -99,7 +99,7 @@ await using var browser = await playwright.Chromium.ConnectAsync("ws://127.0.0.1 If you need to access local servers from within the Docker container: ```bash -docker run --add-host=hostmachine:host-gateway -p 3000:3000 --rm --init -it --workdir /home/pwuser --user pwuser mcr.microsoft.com/playwright:v1.56.0-noble /bin/sh -c "npx -y playwright@1.56.0 run-server --port 3000 --host 0.0.0.0" +docker run --add-host=hostmachine:host-gateway -p 3000:3000 --rm --init -it --workdir /home/pwuser --user pwuser mcr.microsoft.com/playwright:v1.57.0-noble /bin/sh -c "npx -y playwright@1.57.0 run-server --port 3000 --host 0.0.0.0" ``` This makes `hostmachine` point to the host's localhost. Your tests should use `hostmachine` instead of `localhost` when accessing local servers. @@ -114,9 +114,9 @@ When running tests remotely, ensure the Playwright version in your tests matches See [all available image tags]. We currently publish images with the following tags: -- `:v1.56.0` - Playwright v1.56.0 release docker image based on Ubuntu 24.04 LTS (Noble Numbat). -- `:v1.56.0-noble` - Playwright v1.56.0 release docker image based on Ubuntu 24.04 LTS (Noble Numbat). -- `:v1.56.0-jammy` - Playwright v1.56.0 release docker image based on Ubuntu 22.04 LTS (Jammy Jellyfish). +- `:v1.57.0` - Playwright v1.57.0 release docker image based on Ubuntu 24.04 LTS (Noble Numbat). +- `:v1.57.0-noble` - Playwright v1.57.0 release docker image based on Ubuntu 24.04 LTS (Noble Numbat). +- `:v1.57.0-jammy` - Playwright v1.57.0 release docker image based on Ubuntu 22.04 LTS (Jammy Jellyfish). :::note diff --git a/dotnet/docs/release-notes.mdx b/dotnet/docs/release-notes.mdx index bc1d3749aa9..6c4a6eed8d0 100644 --- a/dotnet/docs/release-notes.mdx +++ b/dotnet/docs/release-notes.mdx @@ -7,6 +7,34 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import HTMLCard from '@site/src/components/HTMLCard'; +## Version 1.57 + +### Chrome for Testing + +Starting with this release, Playwright switches from Chromium, to using [Chrome for Testing](https://developer.chrome.com/blog/chrome-for-testing/) builds. Both headed and headless browsers are subject to this. Your tests should still be passing after upgrading to Playwright 1.57. + +We're expecting no functional changes to come from this switch. The biggest change is the new icon and title in your toolbar. + +![new and old logo](../images/cft-logo-change.png) + +If you still see an unexpected behaviour change, please [file an issue](https://github.com/microsoft/playwright/issues/new). + +On Arm64 Linux, Playwright continues to use Chromium. + +### Breaking Change + +After 3 years of being deprecated, we removed `Page.Accessibility` from our API. Please use other libraries such as [Axe](https://www.deque.com/axe/) if you need to test page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for integration with Axe. + +### New APIs +- [Worker.Console](/api/class-worker.mdx#worker-event-console) event is emitted when JavaScript within the worker calls one of console API methods, e.g. console.log or console.dir. +- [Locator.Description](/api/class-locator.mdx#locator-description) returns locator description previously set with [Locator.Describe()](/api/class-locator.mdx#locator-describe). +- New option [Steps](/api/class-locator.mdx#locator-click-option-steps) in [Locator.ClickAsync()](/api/class-locator.mdx#locator-click) and [Locator.DragToAsync()](/api/class-locator.mdx#locator-drag-to) that configures the number of `mousemove` events emitted while moving the mouse pointer to the target element. + +### Browser Versions +- Chromium 143.0.7499.4 +- Mozilla Firefox 144.0.2 +- WebKit 26.0 + ## Version 1.56 ### New APIs diff --git a/java/docs/api/class-browsertype.mdx b/java/docs/api/class-browsertype.mdx index 29864e91827..c830fe70c17 100644 --- a/java/docs/api/class-browsertype.mdx +++ b/java/docs/api/class-browsertype.mdx @@ -186,14 +186,6 @@ Browser browser = chromium.launch(new BrowserType.LaunchOptions() - `setChromiumSandbox` [boolean] *(optional)*# Enable Chromium sandboxing. Defaults to `false`. - - `setDevtools` [boolean] *(optional)*# - - :::warning[Deprecated] - Use [debugging tools](../debug.mdx) instead. - ::: - - - **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the [setHeadless](/api/class-browsertype.mdx#browser-type-launch-option-headless) option will be set `false`. - `setDownloadsPath` [Path] *(optional)*# If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is deleted when browser is closed. In either case, the downloads are deleted when the browser context they were created in is closed. @@ -219,7 +211,7 @@ Browser browser = chromium.launch(new BrowserType.LaunchOptions() Close the browser process on SIGTERM. Defaults to `true`. - `setHeadless` [boolean] *(optional)*# - Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/). Defaults to `true` unless the [setDevtools](/api/class-browsertype.mdx#browser-type-launch-option-devtools) option is `true`. + Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/). Defaults to `true`. - `setIgnoreAllDefaultArgs` [boolean] *(optional)* Added in: v1.9# If `true`, Playwright does not pass its own configurations args and only uses the ones from [setArgs](/api/class-browsertype.mdx#browser-type-launch-option-args). Dangerous option; use with care. Defaults to `false`. @@ -364,14 +356,6 @@ BrowserType.launchPersistentContext(userDataDir, options); - `setDeviceScaleFactor` [double] *(optional)*# Specify device scale factor (can be thought of as dpr). Defaults to `1`. Learn more about [emulating devices with device scale factor](../emulation.mdx#devices). - - `setDevtools` [boolean] *(optional)*# - - :::warning[Deprecated] - Use [debugging tools](../debug.mdx) instead. - ::: - - - **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the [setHeadless](/api/class-browsertype.mdx#browser-type-launch-persistent-context-option-headless) option will be set `false`. - `setDownloadsPath` [Path] *(optional)*# If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is deleted when browser is closed. In either case, the downloads are deleted when the browser context they were created in is closed. @@ -416,7 +400,7 @@ BrowserType.launchPersistentContext(userDataDir, options); Specifies if viewport supports touch events. Defaults to false. Learn more about [mobile emulation](../emulation.mdx#devices). - `setHeadless` [boolean] *(optional)*# - Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/). Defaults to `true` unless the [setDevtools](/api/class-browsertype.mdx#browser-type-launch-option-devtools) option is `true`. + Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/). Defaults to `true`. - `setHttpCredentials` HttpCredentials *(optional)*# - `setUsername` [String] diff --git a/java/docs/ci.mdx b/java/docs/ci.mdx index 4c29ffc3ff1..1ea09503855 100644 --- a/java/docs/ci.mdx +++ b/java/docs/ci.mdx @@ -75,7 +75,7 @@ jobs: name: 'Playwright Tests' runs-on: ubuntu-latest container: - image: mcr.microsoft.com/playwright/java:v1.56.0-noble + image: mcr.microsoft.com/playwright/java:v1.57.0-noble options: --user 1001 steps: - uses: actions/checkout@v5 @@ -160,7 +160,7 @@ trigger: pool: vmImage: ubuntu-latest -container: mcr.microsoft.com/playwright/java:v1.56.0-noble +container: mcr.microsoft.com/playwright/java:v1.57.0-noble steps: - task: JavaToolInstaller@1 @@ -183,7 +183,7 @@ Running Playwright on CircleCI is very similar to running on GitHub Actions. In executors: pw-noble-development: docker: - - image: mcr.microsoft.com/playwright/java:v1.56.0-noble + - image: mcr.microsoft.com/playwright/java:v1.57.0-noble ``` Note: When using the docker agent definition, you are specifying the resource class of where playwright runs to the 'medium' tier [here](https://circleci.com/docs/configuration-reference?#docker-execution-environment). The default behavior of Playwright is to set the number of workers to the detected core count (2 in the case of the medium tier). Overriding the number of workers to greater than this number will cause unnecessary timeouts and failures. @@ -194,7 +194,7 @@ Jenkins supports Docker agents for pipelines. Use the [Playwright Docker image]( ```groovy pipeline { - agent { docker { image 'mcr.microsoft.com/playwright/java:v1.56.0-noble' } } + agent { docker { image 'mcr.microsoft.com/playwright/java:v1.57.0-noble' } } stages { stage('e2e-tests') { steps { @@ -211,7 +211,7 @@ pipeline { Bitbucket Pipelines can use public [Docker images as build environments](https://confluence.atlassian.com/bitbucket/use-docker-images-as-build-environments-792298897.html). To run Playwright tests on Bitbucket, use our public Docker image ([see Dockerfile](./docker.mdx)). ```yml -image: mcr.microsoft.com/playwright/java:v1.56.0-noble +image: mcr.microsoft.com/playwright/java:v1.57.0-noble ``` ### GitLab CI @@ -224,7 +224,7 @@ stages: tests: stage: test - image: mcr.microsoft.com/playwright/java:v1.56.0-noble + image: mcr.microsoft.com/playwright/java:v1.57.0-noble script: ... ``` diff --git a/java/docs/docker.mdx b/java/docs/docker.mdx index 9b2b037da17..8319cb65c48 100644 --- a/java/docs/docker.mdx +++ b/java/docs/docker.mdx @@ -22,7 +22,7 @@ This Docker image is intended to be used for testing and development purposes on ### Pull the image ```bash -docker pull mcr.microsoft.com/playwright/java:v1.56.0-noble +docker pull mcr.microsoft.com/playwright/java:v1.57.0-noble ``` ### Run the image @@ -34,7 +34,7 @@ By default, the Docker image will use the `root` user to run the browsers. This On trusted websites, you can avoid creating a separate user and use root for it since you trust the code which will run on the browsers. ```bash -docker run -it --rm --ipc=host mcr.microsoft.com/playwright/java:v1.56.0-noble /bin/bash +docker run -it --rm --ipc=host mcr.microsoft.com/playwright/java:v1.57.0-noble /bin/bash ``` #### Crawling and scraping @@ -42,7 +42,7 @@ docker run -it --rm --ipc=host mcr.microsoft.com/playwright/java:v1.56.0-noble / On untrusted websites, it's recommended to use a separate user for launching the browsers in combination with the seccomp profile. Inside the container or if you are using the Docker image as a base image you have to use `adduser` for it. ```bash -docker run -it --rm --ipc=host --user pwuser --security-opt seccomp=seccomp_profile.json mcr.microsoft.com/playwright/java:v1.56.0-noble /bin/bash +docker run -it --rm --ipc=host --user pwuser --security-opt seccomp=seccomp_profile.json mcr.microsoft.com/playwright/java:v1.57.0-noble /bin/bash ``` [`seccomp_profile.json`](https://github.com/microsoft/playwright/blob/main/utils/docker/seccomp_profile.json) is needed to run Chromium with sandbox. This is a [default Docker seccomp profile](https://github.com/docker/engine/blob/d0d99b04cf6e00ed3fc27e81fc3d94e7eda70af3/profiles/seccomp/default.json) with extra user namespace cloning permissions: @@ -82,7 +82,7 @@ You can run Playwright Server in Docker while keeping your tests running on the Start the Playwright Server in Docker: ```bash -docker run -p 3000:3000 --rm --init -it --workdir /home/pwuser --user pwuser mcr.microsoft.com/playwright:v1.56.0-noble /bin/sh -c "npx -y playwright@1.56.0 run-server --port 3000 --host 0.0.0.0" +docker run -p 3000:3000 --rm --init -it --workdir /home/pwuser --user pwuser mcr.microsoft.com/playwright:v1.57.0-noble /bin/sh -c "npx -y playwright@1.57.0 run-server --port 3000 --host 0.0.0.0" ``` #### Connecting to the Server @@ -107,7 +107,7 @@ public class App { If you need to access local servers from within the Docker container: ```bash -docker run --add-host=hostmachine:host-gateway -p 3000:3000 --rm --init -it --workdir /home/pwuser --user pwuser mcr.microsoft.com/playwright:v1.56.0-noble /bin/sh -c "npx -y playwright@1.56.0 run-server --port 3000 --host 0.0.0.0" +docker run --add-host=hostmachine:host-gateway -p 3000:3000 --rm --init -it --workdir /home/pwuser --user pwuser mcr.microsoft.com/playwright:v1.57.0-noble /bin/sh -c "npx -y playwright@1.57.0 run-server --port 3000 --host 0.0.0.0" ``` This makes `hostmachine` point to the host's localhost. Your tests should use `hostmachine` instead of `localhost` when accessing local servers. @@ -122,9 +122,9 @@ When running tests remotely, ensure the Playwright version in your tests matches See [all available image tags]. We currently publish images with the following tags: -- `:v1.56.0` - Playwright v1.56.0 release docker image based on Ubuntu 24.04 LTS (Noble Numbat). -- `:v1.56.0-noble` - Playwright v1.56.0 release docker image based on Ubuntu 24.04 LTS (Noble Numbat). -- `:v1.56.0-jammy` - Playwright v1.56.0 release docker image based on Ubuntu 22.04 LTS (Jammy Jellyfish). +- `:v1.57.0` - Playwright v1.57.0 release docker image based on Ubuntu 24.04 LTS (Noble Numbat). +- `:v1.57.0-noble` - Playwright v1.57.0 release docker image based on Ubuntu 24.04 LTS (Noble Numbat). +- `:v1.57.0-jammy` - Playwright v1.57.0 release docker image based on Ubuntu 22.04 LTS (Jammy Jellyfish). :::note diff --git a/java/docs/intro.mdx b/java/docs/intro.mdx index f2dfcae2e9f..c987e6efcd3 100644 --- a/java/docs/intro.mdx +++ b/java/docs/intro.mdx @@ -58,7 +58,7 @@ public class App { com.microsoft.playwright playwright - 1.56.0 + 1.57.0 diff --git a/java/docs/locators.mdx b/java/docs/locators.mdx index 434417c3262..0dee6602a99 100644 --- a/java/docs/locators.mdx +++ b/java/docs/locators.mdx @@ -470,7 +470,7 @@ page.getByRole(AriaRole.LISTITEM) .filter(new Locator.FilterOptions() .setHasText(Pattern.compile("Product 2"))) .getByRole(AriaRole.BUTTON, - new Page.GetByRoleOptions().setName("Add to cart")) + new Locator.GetByRoleOptions().setName("Add to cart")) .click(); ``` @@ -533,7 +533,7 @@ We can also assert the product card to make sure there is only one: assertThat(page .getByRole(AriaRole.LISTITEM) .filter(new Locator.FilterOptions() - .setHas(page.GetByRole(AriaRole.HEADING, + .setHas(page.getByRole(AriaRole.HEADING, new Page.GetByRoleOptions().setName("Product 2"))))) .hasCount(1); ``` diff --git a/java/docs/release-notes.mdx b/java/docs/release-notes.mdx index e0cb4b53dd6..5b728b4c895 100644 --- a/java/docs/release-notes.mdx +++ b/java/docs/release-notes.mdx @@ -7,6 +7,34 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import HTMLCard from '@site/src/components/HTMLCard'; +## Version 1.57 + +### Chrome for Testing + +Starting with this release, Playwright switches from Chromium, to using [Chrome for Testing](https://developer.chrome.com/blog/chrome-for-testing/) builds. Both headed and headless browsers are subject to this. Your tests should still be passing after upgrading to Playwright 1.57. + +We're expecting no functional changes to come from this switch. The biggest change is the new icon and title in your toolbar. + +![new and old logo](../images/cft-logo-change.png) + +If you still see an unexpected behaviour change, please [file an issue](https://github.com/microsoft/playwright/issues/new). + +On Arm64 Linux, Playwright continues to use Chromium. + +### Breaking Change + +After 3 years of being deprecated, we removed `page.accessibility()` from our API. Please use other libraries such as [Axe](https://www.deque.com/axe/) if you need to test page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for integration with Axe. + +### New APIs +- [Worker.onConsole(handler)](/api/class-worker.mdx#worker-event-console) event is emitted when JavaScript within the worker calls one of console API methods, e.g. console.log or console.dir. [Worker.waitForConsoleMessage()](/api/class-worker.mdx#worker-wait-for-console-message) can be used to wait for it. +- [Locator.description()](/api/class-locator.mdx#locator-description) returns locator description previously set with [Locator.describe()](/api/class-locator.mdx#locator-describe). +- New option [setSteps](/api/class-locator.mdx#locator-click-option-steps) in [Locator.click()](/api/class-locator.mdx#locator-click) and [Locator.dragTo()](/api/class-locator.mdx#locator-drag-to) that configures the number of `mousemove` events emitted while moving the mouse pointer to the target element. + +### Browser Versions +- Chromium 143.0.7499.4 +- Mozilla Firefox 144.0.2 +- WebKit 26.0 + ## Version 1.56 ### New APIs diff --git a/java/docs/test-runners.mdx b/java/docs/test-runners.mdx index b170f8debb1..c139ed7df66 100644 --- a/java/docs/test-runners.mdx +++ b/java/docs/test-runners.mdx @@ -198,7 +198,7 @@ repositories { } dependencies { - implementation 'com.microsoft.playwright:playwright:1.56.0' + implementation 'com.microsoft.playwright:playwright:1.57.0' } application { @@ -231,7 +231,7 @@ repositories { } dependencies { - implementation("com.microsoft.playwright:playwright:1.56.0") + implementation("com.microsoft.playwright:playwright:1.57.0") } application { diff --git a/nodejs/docs/api/class-browsertype.mdx b/nodejs/docs/api/class-browsertype.mdx index ff8b676b9a9..83bca58e8b6 100644 --- a/nodejs/docs/api/class-browsertype.mdx +++ b/nodejs/docs/api/class-browsertype.mdx @@ -203,14 +203,6 @@ const browser = await chromium.launch({ // Or 'firefox' or 'webkit'. - `chromiumSandbox` [boolean] *(optional)*# Enable Chromium sandboxing. Defaults to `false`. - - `devtools` [boolean] *(optional)*# - - :::warning[Deprecated] - Use [debugging tools](../debug.mdx) instead. - ::: - - - **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the [headless](/api/class-browsertype.mdx#browser-type-launch-option-headless) option will be set `false`. - `downloadsPath` [string] *(optional)*# If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is deleted when browser is closed. In either case, the downloads are deleted when the browser context they were created in is closed. @@ -234,7 +226,7 @@ const browser = await chromium.launch({ // Or 'firefox' or 'webkit'. Close the browser process on SIGTERM. Defaults to `true`. - `headless` [boolean] *(optional)*# - Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/). Defaults to `true` unless the [devtools](/api/class-browsertype.mdx#browser-type-launch-option-devtools) option is `true`. + Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/). Defaults to `true`. - `ignoreDefaultArgs` [boolean] | [Array]<[string]> *(optional)*# If `true`, Playwright does not pass its own configurations args and only uses the ones from [args](/api/class-browsertype.mdx#browser-type-launch-option-args). If an array is given, then filters out the given default arguments. Dangerous option; use with care. Defaults to `false`. @@ -384,14 +376,6 @@ await browserType.launchPersistentContext(userDataDir, options); - `deviceScaleFactor` [number] *(optional)*# Specify device scale factor (can be thought of as dpr). Defaults to `1`. Learn more about [emulating devices with device scale factor](../emulation.mdx#devices). - - `devtools` [boolean] *(optional)*# - - :::warning[Deprecated] - Use [debugging tools](../debug.mdx) instead. - ::: - - - **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the [headless](/api/class-browsertype.mdx#browser-type-launch-persistent-context-option-headless) option will be set `false`. - `downloadsPath` [string] *(optional)*# If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is deleted when browser is closed. In either case, the downloads are deleted when the browser context they were created in is closed. @@ -434,7 +418,7 @@ await browserType.launchPersistentContext(userDataDir, options); Specifies if viewport supports touch events. Defaults to false. Learn more about [mobile emulation](../emulation.mdx#devices). - `headless` [boolean] *(optional)*# - Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/). Defaults to `true` unless the [devtools](/api/class-browsertype.mdx#browser-type-launch-option-devtools) option is `true`. + Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/). Defaults to `true`. - `httpCredentials` [Object] *(optional)*# - `username` [string] @@ -643,14 +627,6 @@ const { chromium } = require('playwright'); // Or 'webkit' or 'firefox'. - `chromiumSandbox` [boolean] *(optional)*# Enable Chromium sandboxing. Defaults to `false`. - - `devtools` [boolean] *(optional)*# - - :::warning[Deprecated] - Use [debugging tools](../debug.mdx) instead. - ::: - - - **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the [headless](/api/class-browsertype.mdx#browser-type-launch-server-option-headless) option will be set `false`. - `downloadsPath` [string] *(optional)*# If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is deleted when browser is closed. In either case, the downloads are deleted when the browser context they were created in is closed. @@ -674,7 +650,7 @@ const { chromium } = require('playwright'); // Or 'webkit' or 'firefox'. Close the browser process on SIGTERM. Defaults to `true`. - `headless` [boolean] *(optional)*# - Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/). Defaults to `true` unless the [devtools](/api/class-browsertype.mdx#browser-type-launch-option-devtools) option is `true`. + Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/). Defaults to `true`. - `host` [string] *(optional)* Added in: v1.45# Host to use for the web socket. It is optional and if it is omitted, the server will accept connections on the unspecified IPv6 address (::) when IPv6 is available, or the unspecified IPv4 address (0.0.0.0) otherwise. Consider hardening it with picking a specific interface. diff --git a/nodejs/docs/api/class-consolemessage.mdx b/nodejs/docs/api/class-consolemessage.mdx index 508766af369..ce10419b8cb 100644 --- a/nodejs/docs/api/class-consolemessage.mdx +++ b/nodejs/docs/api/class-consolemessage.mdx @@ -122,7 +122,7 @@ consoleMessage.type(); ``` **Returns** -- "log" | "debug" | "info" | "error" | "warning" | "dir" | "dirxml" | "table" | "trace" | "clear" | "startGroup" | "startGroupCollapsed" | "endGroup" | "assert" | "profile" | "profileEnd" | "count" | "timeEnd"# +- "log" | "debug" | "info" | "error" | "warning" | "dir" | "dirxml" | "table" | "trace" | "clear" | "startGroup" | "startGroupCollapsed" | "endGroup" | "assert" | "profile" | "profileEnd" | "count" | "time" | "timeEnd"# --- diff --git a/nodejs/docs/api/class-testoptions.mdx b/nodejs/docs/api/class-testoptions.mdx index 022953ddf98..6e108dd1698 100644 --- a/nodejs/docs/api/class-testoptions.mdx +++ b/nodejs/docs/api/class-testoptions.mdx @@ -454,7 +454,7 @@ export default defineConfig({ Added in: v1.10testOptions.headless -Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/). Defaults to `true` unless the [devtools](/api/class-browsertype.mdx#browser-type-launch-option-devtools) option is `true`. +Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/). Defaults to `true`. **Usage** diff --git a/nodejs/docs/release-notes.mdx b/nodejs/docs/release-notes.mdx index 9d9fe7e7d32..f4bee905bfb 100644 --- a/nodejs/docs/release-notes.mdx +++ b/nodejs/docs/release-notes.mdx @@ -64,7 +64,7 @@ This is not just useful for capturing varying ports of dev servers. You can also ### Breaking Change -After 3 years of being deprecated, we removed `Page#accessibility` from our API. Please use other libraries such as [Axe](https://www.deque.com/axe/) if you need to test page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for integration with Axe. +After 3 years of being deprecated, we removed `page.accessibility` from our API. Please use other libraries such as [Axe](https://www.deque.com/axe/) if you need to test page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for integration with Axe. ### New APIs - New property [testConfig.tag](/api/class-testconfig.mdx#test-config-tag) adds a tag to all tests in this run. This is useful when using [merge-reports](./test-sharding.mdx#merging-reports-from-multiple-shards). @@ -76,7 +76,7 @@ After 3 years of being deprecated, we removed `Page#accessibility` from our API. ### Browser Versions - Chromium 143.0.7499.4 -- Mozilla Firefox 142.0.1 +- Mozilla Firefox 144.0.2 - WebKit 26.0 ## Version 1.56 diff --git a/python/docs/api/class-browsertype.mdx b/python/docs/api/class-browsertype.mdx index bf6bc4810dc..60287b0f5cf 100644 --- a/python/docs/api/class-browsertype.mdx +++ b/python/docs/api/class-browsertype.mdx @@ -242,14 +242,6 @@ browser = await playwright.chromium.launch( # or "firefox" or "webkit". - `chromium_sandbox` [bool] *(optional)*# Enable Chromium sandboxing. Defaults to `false`. -- `devtools` [bool] *(optional)*# - - :::warning[Deprecated] - Use [debugging tools](../debug.mdx) instead. - ::: - - - **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the [headless](/api/class-browsertype.mdx#browser-type-launch-option-headless) option will be set `false`. - `downloads_path` [Union]\[[str], [pathlib.Path]\] *(optional)*# If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is deleted when browser is closed. In either case, the downloads are deleted when the browser context they were created in is closed. @@ -275,7 +267,7 @@ browser = await playwright.chromium.launch( # or "firefox" or "webkit". Close the browser process on SIGTERM. Defaults to `true`. - `headless` [bool] *(optional)*# - Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/). Defaults to `true` unless the [devtools](/api/class-browsertype.mdx#browser-type-launch-option-devtools) option is `true`. + Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/). Defaults to `true`. - `ignore_default_args` [bool] | [List]\[[str]\] *(optional)*# If `true`, Playwright does not pass its own configurations args and only uses the ones from [args](/api/class-browsertype.mdx#browser-type-launch-option-args). If an array is given, then filters out the given default arguments. Dangerous option; use with care. Defaults to `false`. @@ -416,14 +408,6 @@ browser_type.launch_persistent_context(user_data_dir, **kwargs) - `device_scale_factor` [float] *(optional)*# Specify device scale factor (can be thought of as dpr). Defaults to `1`. Learn more about [emulating devices with device scale factor](../emulation.mdx#devices). -- `devtools` [bool] *(optional)*# - - :::warning[Deprecated] - Use [debugging tools](../debug.mdx) instead. - ::: - - - **Chromium-only** Whether to auto-open a Developer Tools panel for each tab. If this option is `true`, the [headless](/api/class-browsertype.mdx#browser-type-launch-persistent-context-option-headless) option will be set `false`. - `downloads_path` [Union]\[[str], [pathlib.Path]\] *(optional)*# If specified, accepted downloads are downloaded into this directory. Otherwise, temporary directory is created and is deleted when browser is closed. In either case, the downloads are deleted when the browser context they were created in is closed. @@ -468,7 +452,7 @@ browser_type.launch_persistent_context(user_data_dir, **kwargs) Specifies if viewport supports touch events. Defaults to false. Learn more about [mobile emulation](../emulation.mdx#devices). - `headless` [bool] *(optional)*# - Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/). Defaults to `true` unless the [devtools](/api/class-browsertype.mdx#browser-type-launch-option-devtools) option is `true`. + Whether to run browser in headless mode. More details for [Chromium](https://developers.google.com/web/updates/2017/04/headless-chrome) and [Firefox](https://hacks.mozilla.org/2017/12/using-headless-mode-in-firefox/). Defaults to `true`. - `http_credentials` [Dict] *(optional)*# - `username` [str] diff --git a/python/docs/api/class-consolemessage.mdx b/python/docs/api/class-consolemessage.mdx index 6996f8f1cb6..4ea4500ed7b 100644 --- a/python/docs/api/class-consolemessage.mdx +++ b/python/docs/api/class-consolemessage.mdx @@ -152,7 +152,7 @@ console_message.type ``` **Returns** -- "log" | "debug" | "info" | "error" | "warning" | "dir" | "dirxml" | "table" | "trace" | "clear" | "startGroup" | "startGroupCollapsed" | "endGroup" | "assert" | "profile" | "profileEnd" | "count" | "timeEnd"# +- "log" | "debug" | "info" | "error" | "warning" | "dir" | "dirxml" | "table" | "trace" | "clear" | "startGroup" | "startGroupCollapsed" | "endGroup" | "assert" | "profile" | "profileEnd" | "count" | "time" | "timeEnd"# --- diff --git a/python/docs/api/class-request.mdx b/python/docs/api/class-request.mdx index 6f047b19a30..5dcc69043a4 100644 --- a/python/docs/api/class-request.mdx +++ b/python/docs/api/class-request.mdx @@ -393,6 +393,29 @@ request.resource_type --- +### service_worker {#request-service-worker} + +Added in: v1.24request.service_worker + +The Service [Worker] that is performing the request. + +**Usage** + +```python +request.service_worker +``` + +**Returns** +- [NoneType] | [Worker]# + +**Details** + +This method is Chromium only. It's safe to call when using other browsers, but it will always be `null`. + +Requests originated in a Service Worker do not have a [request.frame](/api/class-request.mdx#request-frame) available. + +--- + ### timing {#request-timing} Added before v1.9request.timing diff --git a/python/docs/release-notes.mdx b/python/docs/release-notes.mdx index d58382dadce..4e812e15f85 100644 --- a/python/docs/release-notes.mdx +++ b/python/docs/release-notes.mdx @@ -7,6 +7,36 @@ import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; import HTMLCard from '@site/src/components/HTMLCard'; +## Version 1.57 + +### Chrome for Testing + +Starting with this release, Playwright switches from Chromium, to using [Chrome for Testing](https://developer.chrome.com/blog/chrome-for-testing/) builds. Both headed and headless browsers are subject to this. Your tests should still be passing after upgrading to Playwright 1.57. + +We're expecting no functional changes to come from this switch. The biggest change is the new icon and title in your toolbar. + +![new and old logo](../images/cft-logo-change.png) + +If you still see an unexpected behaviour change, please [file an issue](https://github.com/microsoft/playwright/issues/new). + +On Arm64 Linux, Playwright continues to use Chromium. + +### Breaking Change + +After 3 years of being deprecated, we removed `page.accessibility` from our API. Please use other libraries such as [Axe](https://www.deque.com/axe/) if you need to test page accessibility. See our Node.js [guide](https://playwright.dev/docs/accessibility-testing) for integration with Axe. + +### New APIs +- [worker.on("console")](/api/class-worker.mdx#worker-event-console) event is emitted when JavaScript within the worker calls one of console API methods, e.g. console.log or console.dir. [worker.expect_event()](/api/class-worker.mdx#worker-wait-for-event) can be used to wait for it. +- [locator.description](/api/class-locator.mdx#locator-description) returns locator description previously set with [locator.describe()](/api/class-locator.mdx#locator-describe). +- New option [steps](/api/class-locator.mdx#locator-click-option-steps) in [locator.click()](/api/class-locator.mdx#locator-click) and [locator.drag_to()](/api/class-locator.mdx#locator-drag-to) that configures the number of `mousemove` events emitted while moving the mouse pointer to the target element. +- Network requests issued by [Service Workers](./service-workers.mdx#network-events-and-routing) are now reported and can be routed through the [BrowserContext](./api/class-browsercontext.mdx), only in Chromium. You can opt out using the `PLAYWRIGHT_DISABLE_SERVICE_WORKER_NETWORK` environment variable. +- Console messages from Service Workers are dispatched through [worker.on("console")](/api/class-worker.mdx#worker-event-console). You can opt out of this using the `PLAYWRIGHT_DISABLE_SERVICE_WORKER_CONSOLE` environment variable. + +### Browser Versions +- Chromium 143.0.7499.4 +- Mozilla Firefox 144.0.2 +- WebKit 26.0 + ## Version 1.56 ### New APIs diff --git a/python/docs/service-workers.mdx b/python/docs/service-workers.mdx new file mode 100644 index 00000000000..c3180e09b38 --- /dev/null +++ b/python/docs/service-workers.mdx @@ -0,0 +1,262 @@ +--- +id: service-workers +title: "Service Workers" +--- +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; +import HTMLCard from '@site/src/components/HTMLCard'; + +## Introduction + +:::warning + +Service workers are only supported on Chromium-based browsers. +::: + +:::note +If you're looking to do general network mocking, routing, and interception, please see the [Network Guide](./network.mdx) first. Playwright provides built-in APIs for this use case that don't require the information below. However, if you're interested in requests made by Service Workers themselves, please read below. +::: + +[Service Workers](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API) provide a browser-native method of handling requests made by a page with the native [Fetch API (`fetch`)](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) along with other network-requested assets (like scripts, css, and images). + +They can act as a **network proxy** between the page and the external network to perform caching logic or can provide users with an offline experience if the Service Worker adds a [FetchEvent](https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent#examples) listener. + +Many sites that use Service Workers simply use them as a transparent optimization technique. While users might notice a faster experience, the app's implementation is unaware of their existence. Running the app with or without Service Workers enabled appears functionally equivalent. + +## How to Disable Service Workers + +Playwright allows to disable Service Workers during testing. This makes tests more predictable and performant. However, if your actual page uses a Service Worker, the behavior might be different. + +To disable service workers, set `service_workers` context option to `"block"`. + +```python title="conftest.py" +import pytest + +@pytest.fixture(scope="session") +def browser_context_args(browser_context_args): + return { + **browser_context_args, + "service_workers": "block" + } +``` + +## Accessing Service Workers and Waiting for Activation + +You can use [browser_context.service_workers](/api/class-browsercontext.mdx#browser-context-service-workers) to list the Service [Worker]s, or specifically watch for the Service [Worker] if you anticipate a page will trigger its [registration](https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerContainer/register): + + + + +```py +with context.expect_event("serviceworker") as worker_info: + page.goto("/example-with-a-service-worker.html") +service_worker = worker_info.value +``` + + + + +```py +async with context.expect_event("serviceworker") as worker_info: + await page.goto("/example-with-a-service-worker.html") +service_worker = await worker_info.value +``` + + + + +[browser_context.on("serviceworker")](/api/class-browsercontext.mdx#browser-context-event-service-worker) event is fired ***before*** the Service Worker has taken control over the page, so ***before*** evaluating in the worker with [worker.evaluate()](/api/class-worker.mdx#worker-evaluate) you should wait on its activation. + +There are more idiomatic methods of waiting for a Service Worker to be activated, but the following is an implementation agnostic method: + + + + +```py +page.evaluate("""async () => { + const registration = await window.navigator.serviceWorker.getRegistration(); + if (registration.active?.state === 'activated') + return; + await new Promise(resolve => { + window.navigator.serviceWorker.addEventListener('controllerchange', resolve); + }); +}""") +``` + + + + +```py +await page.evaluate("""async () => { + const registration = await window.navigator.serviceWorker.getRegistration(); + if (registration.active?.state === 'activated') + return; + await new Promise(resolve => { + window.navigator.serviceWorker.addEventListener('controllerchange', resolve); + }); +}""") +``` + + + + +## Network Events and Routing + +Any network request made by the **Service Worker** is reported through the [BrowserContext] object: +* [browser_context.on("request")](/api/class-browsercontext.mdx#browser-context-event-request), [browser_context.on("requestfinished")](/api/class-browsercontext.mdx#browser-context-event-request-finished), [browser_context.on("response")](/api/class-browsercontext.mdx#browser-context-event-response) and [browser_context.on("requestfailed")](/api/class-browsercontext.mdx#browser-context-event-request-failed) are fired +* [browser_context.route()](/api/class-browsercontext.mdx#browser-context-route) sees the request +* [request.service_worker](/api/class-request.mdx#request-service-worker) will be set to the Service [Worker] instance, and [request.frame](/api/class-request.mdx#request-frame) will **throw** + +Additionally, for any network request made by the **Page**, method [response.from_service_worker](/api/class-response.mdx#response-from-service-worker) return `true` when the request was handled a Service Worker's fetch handler. + +Consider a simple service worker that fetches every request made by the page: + +If `index.html` registers this service worker, and then fetches `data.json`, the following Request/Response events would be emitted (along with the corresponding network lifecycle events): + +| Event | Owner | URL | Routed | [response.from_service_worker](/api/class-response.mdx#response-from-service-worker) | +| - | - | - | - | - | +| [browser_context.on("request")](/api/class-browsercontext.mdx#browser-context-event-request) | [Frame] | index.html | Yes | | +| [page.on("request")](/api/class-page.mdx#page-event-request) | [Frame] | index.html | Yes | | +| [browser_context.on("request")](/api/class-browsercontext.mdx#browser-context-event-request) | Service [Worker] | transparent-service-worker.js | Yes | | +| [browser_context.on("request")](/api/class-browsercontext.mdx#browser-context-event-request) | Service [Worker] | data.json | Yes | | +| [browser_context.on("request")](/api/class-browsercontext.mdx#browser-context-event-request) | [Frame] | data.json | | Yes | +| [page.on("request")](/api/class-page.mdx#page-event-request) | [Frame] | data.json | | Yes | + +Since the example Service Worker just acts a basic transparent "proxy": +* There's 2 [browser_context.on("request")](/api/class-browsercontext.mdx#browser-context-event-request) events for `data.json`; one [Frame]-owned, the other Service [Worker]-owned. +* Only the Service [Worker]-owned request for the resource was routable via [browser_context.route()](/api/class-browsercontext.mdx#browser-context-route); the [Frame]-owned events for `data.json` are not routeable, as they would not have even had the possibility to hit the external network since the Service Worker has a fetch handler registered. + +:::caution + +It's important to note: calling [request.frame](/api/class-request.mdx#request-frame) or [response.frame](/api/class-response.mdx#response-frame) will **throw** an exception, if called on a [Request]/[Response] that has a non-null [request.service_worker](/api/class-request.mdx#request-service-worker). +::: + +## Routing Service Worker Requests Only + + + + +```py +def handle_route(route: Route): + if route.request.service_worker: + # NB: accessing route.request.frame here would THROW + route.fulfill(content_type="text/plain", status=200, body="from sw") + else: + route.continue_() + +context.route("**", handle_route) +``` + + + + +```py +async def handle_route(route: Route): + if route.request.service_worker: + # NB: accessing route.request.frame here would THROW + await route.fulfill(content_type="text/plain", status=200, body="from sw") + else: + await route.continue_() + +await context.route("**", handle_route) +``` + + + + +## Known Limitations + +Requests for updated Service Worker main script code currently cannot be routed (https://github.com/microsoft/playwright/issues/14711). + + +[APIRequest]: /api/class-apirequest.mdx "APIRequest" +[APIRequestContext]: /api/class-apirequestcontext.mdx "APIRequestContext" +[APIResponse]: /api/class-apiresponse.mdx "APIResponse" +[APIResponseAssertions]: /api/class-apiresponseassertions.mdx "APIResponseAssertions" +[Browser]: /api/class-browser.mdx "Browser" +[BrowserContext]: /api/class-browsercontext.mdx "BrowserContext" +[BrowserType]: /api/class-browsertype.mdx "BrowserType" +[CDPSession]: /api/class-cdpsession.mdx "CDPSession" +[Clock]: /api/class-clock.mdx "Clock" +[ConsoleMessage]: /api/class-consolemessage.mdx "ConsoleMessage" +[Dialog]: /api/class-dialog.mdx "Dialog" +[Download]: /api/class-download.mdx "Download" +[ElementHandle]: /api/class-elementhandle.mdx "ElementHandle" +[Error]: /api/class-error.mdx "Error" +[FileChooser]: /api/class-filechooser.mdx "FileChooser" +[Frame]: /api/class-frame.mdx "Frame" +[FrameLocator]: /api/class-framelocator.mdx "FrameLocator" +[JSHandle]: /api/class-jshandle.mdx "JSHandle" +[Keyboard]: /api/class-keyboard.mdx "Keyboard" +[Locator]: /api/class-locator.mdx "Locator" +[LocatorAssertions]: /api/class-locatorassertions.mdx "LocatorAssertions" +[Mouse]: /api/class-mouse.mdx "Mouse" +[Page]: /api/class-page.mdx "Page" +[PageAssertions]: /api/class-pageassertions.mdx "PageAssertions" +[Playwright]: /api/class-playwright.mdx "Playwright" +[Request]: /api/class-request.mdx "Request" +[Response]: /api/class-response.mdx "Response" +[Route]: /api/class-route.mdx "Route" +[Selectors]: /api/class-selectors.mdx "Selectors" +[TimeoutError]: /api/class-timeouterror.mdx "TimeoutError" +[Touchscreen]: /api/class-touchscreen.mdx "Touchscreen" +[Tracing]: /api/class-tracing.mdx "Tracing" +[Video]: /api/class-video.mdx "Video" +[WebError]: /api/class-weberror.mdx "WebError" +[WebSocket]: /api/class-websocket.mdx "WebSocket" +[WebSocketRoute]: /api/class-websocketroute.mdx "WebSocketRoute" +[Worker]: /api/class-worker.mdx "Worker" +[Element]: https://developer.mozilla.org/en-US/docs/Web/API/element "Element" +[EvaluationArgument]: /evaluating.mdx#evaluation-argument "EvaluationArgument" +[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise" +[iterator]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols "Iterator" +[origin]: https://developer.mozilla.org/en-US/docs/Glossary/Origin "Origin" +[selector]: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors "selector" +[Serializable]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description "Serializable" +[UIEvent.detail]: https://developer.mozilla.org/en-US/docs/Web/API/UIEvent/detail "UIEvent.detail" +[UnixTime]: https://en.wikipedia.org/wiki/Unix_time "Unix Time" +[xpath]: https://developer.mozilla.org/en-US/docs/Web/XPath "xpath" + +[Any]: https://docs.python.org/3/library/typing.html#typing.Any "Any" +[bool]: https://docs.python.org/3/library/stdtypes.html "bool" +[bytes]: https://docs.python.org/3/library/stdtypes.html#bytes "bytes" +[Callable]: https://docs.python.org/3/library/typing.html#typing.Callable "Callable" +[EventContextManager]: https://docs.python.org/3/reference/datamodel.html#context-managers "Event context manager" +[EventEmitter]: https://pyee.readthedocs.io/en/latest/#pyee.BaseEventEmitter "EventEmitter" +[Exception]: https://docs.python.org/3/library/exceptions.html#Exception "Exception" +[Dict]: https://docs.python.org/3/library/typing.html#typing.Dict "Dict" +[float]: https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "float" +[int]: https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex "int" +[List]: https://docs.python.org/3/library/typing.html#typing.List "List" +[NoneType]: https://docs.python.org/3/library/constants.html#None "None" +[Pattern]: https://docs.python.org/3/library/re.html "Pattern" +[URL]: https://en.wikipedia.org/wiki/URL "URL" +[pathlib.Path]: https://realpython.com/python-pathlib/ "pathlib.Path" +[str]: https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str "str" +[Union]: https://docs.python.org/3/library/typing.html#typing.Union "Union" +[datetime]: https://docs.python.org/3/library/datetime.html#datetime.datetime "datetime" + +[all available image tags]: https://mcr.microsoft.com/en-us/product/playwright/python/about "all available image tags" +[Microsoft Artifact Registry]: https://mcr.microsoft.com/en-us/product/playwright/python/about "Microsoft Artifact Registry" +[Dockerfile.noble]: https://github.com/microsoft/playwright-python/blob/main/utils/docker/Dockerfile.noble "Dockerfile.noble"