Playwright

Latest version: v1.48.0

Safety actively analyzes 681775 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 1 of 17

1.48.0

WebSocket routing

New methods [page.route_web_socket()](https://playwright.dev/python/docs/api/class-page#page-route-web-socket) and [browser_context.route_web_socket()](https://playwright.dev/python/docs/api/class-browsercontext#browser-context-route-web-socket) allow to intercept, modify and mock WebSocket connections initiated in the page. Below is a simple example that mocks WebSocket communication by responding to a `"request"` with a `"response"`.

python
def message_handler(ws: WebSocketRoute, message: Union[str, bytes]):
if message == "request":
ws.send("response")

page.route_web_socket("/ws", lambda ws: ws.on_message(
lambda message: message_handler(ws, message)
))


See [WebSocketRoute](https://playwright.dev/python/docs/api/class-websocketroute) for more details.

UI updates
- New "copy" buttons for annotations and test location in the HTML report.
- Route method calls like [route.fulfill()](https://playwright.dev/python/docs/api/class-route#route-fulfill) are not shown in the report and trace viewer anymore. You can see which network requests were routed in the network tab instead.
- New "Copy as cURL" and "Copy as fetch" buttons for requests in the network tab.

Miscellaneous
- New method [page.request_gc()](https://playwright.dev/python/docs/api/class-page#page-request-gc) may help detect memory leaks.
- Requests made by [APIRequestContext](https://playwright.dev/python/docs/api/class-apirequestcontext) now record detailed timing and security information in the HAR.
- This version adds support for Python 3.13
- This version is the last version supporting Python 3.8

Browser Versions
- Chromium 130.0.6723.19
- Mozilla Firefox 130.0
- WebKit 18.0

This version was also tested against the following stable channels:
- Google Chrome 129
- Microsoft Edge 129

1.47.0

Network Tab improvements

The Network tab in the trace viewer has several nice improvements:
- filtering by asset type and URL
- better display of query string parameters
- preview of font assets

![Network tab now has filters](https://github.com/user-attachments/assets/4bd1b67d-90bd-438b-a227-00b9e86872e2)

Miscellaneous
- The `mcr.microsoft.com/playwright-python:v1.47.0` now serves a Playwright image based on Ubuntu 24.04 Noble.
To use the 22.04 jammy-based image, please use `mcr.microsoft.com/playwright-python:v1.47.0-jammy` instead.
- The `:latest`/`:focal`/`:jammy` tag for Playwright Docker images is no longer being published. Pin to a specific version for better stability and reproducibility.
- TLS client certificates can now be passed from memory by passing `cert` and `key` as bytes instead of file paths.
- `no_wait_after` in [locator.selectOption()](https://playwright.dev/python/docs/api/class-locator#locator-select-option) was deprecated.
- We've seen reports of WebGL in Webkit misbehaving on GitHub Actions `macos-13`. We recommend upgrading GitHub Actions to `macos-14`.

Browser Versions
- Chromium 129.0.6668.29
- Mozilla Firefox 130.0
- WebKit 18.0

This version was also tested against the following stable channels:
- Google Chrome 128
- Microsoft Edge 128

1.46.0

TLS Client Certificates

Playwright now allows to supply client-side certificates, so that server can verify them, as specified by TLS Client Authentication.

You can provide client certificates as a parameter of [browser.new_context()](https://playwright.dev/python/docs/api/class-browser#browser-new-context) and [api_request.new_context()](https://playwright.dev/python/docs/api/class-apirequest#api-request-new-context). The following snippet sets up a client certificate for `https://example.com`:

python
context = browser.new_context(
client_certificates=[
{
"origin": "https://example.com",
"certPath": "client-certificates/cert.pem",
"keyPath": "client-certificates/key.pem",
}
],
)


When using the [Pytest plugin](https://playwright.dev/python/docs/test-runners), it can be added like this:

python
pytest.fixture(scope="session")
def browser_context_args(browser_context_args):
return {
**browser_context_args,
"client_certificates": [
{
"origin": "https://example.com",
"certPath": "client-certificates/cert.pem",
"keyPath": "client-certificates/key.pem",
}
],
}


Trace Viewer Updates
- Content of text attachments is now rendered inline in the attachments pane.
- New setting to show/hide routing actions like [route.continue_()](https://playwright.dev/python/docs/api/class-route#route-continue).
- Request method and status are shown in the network details tab.
- New button to copy source file location to clipboard.
- Metadata pane now displays the `base_url`.

Miscellaneous
- New `max_retries` option in [apiRequestContext.fetch()](https://playwright.dev/python/docs/api/class-apirequestcontext#api-request-context-fetch) which retries on the `ECONNRESET` network error.

Browser Versions
- Chromium 128.0.6613.18
- Mozilla Firefox 128.0
- WebKit 18.0

This version was also tested against the following stable channels:
- Google Chrome 127
- Microsoft Edge 127

1.45.1

Highlights

https://github.com/microsoft/playwright-java/issues/1617 - [Bug]: Trace Viewer not reporting all actions
https://github.com/microsoft/playwright/issues/31764 - [Bug]: some actions do not appear in the trace file

Browser Versions

* Chromium 127.0.6533.5
* Mozilla Firefox 127.0
* WebKit 17.4

This version was also tested against the following stable channels:
* Google Chrome 126
* Microsoft Edge 126

1.45.0

Clock

Utilizing the new [Clock](https://playwright.dev/python/docs/api/class-clock) API allows to manipulate and control time within tests to verify time-related behavior. This API covers many common scenarios, including:
* testing with predefined time;
* keeping consistent time and timers;
* monitoring inactivity;
* ticking through time manually.

python
Initialize clock with some time before the test time and let the page load
naturally. `Date.now` will progress as the timers fire.
page.clock.install(time=datetime.datetime(2024, 2, 2, 8, 0, 0))
page.goto("http://localhost:3333")

Pretend that the user closed the laptop lid and opened it again at 10am.
Pause the time once reached that point.
page.clock.pause_at(datetime.datetime(2024, 2, 2, 10, 0, 0))

Assert the page state.
expect(page.get_by_test_id("current-time")).to_have_text("2/2/2024, 10:00:00 AM")

Close the laptop lid again and open it at 10:30am.
page.clock.fast_forward("30:00")
expect(page.get_by_test_id("current-time")).to_have_text("2/2/2024, 10:30:00 AM")


See [the clock guide](https://playwright.dev/python/docs/clock) for more details.

Miscellaneous
- Method [locator.setInputFiles()](https://playwright.dev/python/docs/api/class-locator#locator-set-input-files) now supports uploading a directory for `<input type=file webkitdirectory>` elements.
python
page.get_by_label("Upload directory").set_input_files('mydir')

- Multiple methods like [locator.click()](https://playwright.dev/python/docs/api/class-locator#locator-click) or [locator.press()](https://playwright.dev/python/docs/api/class-locator#locator-press) now support a `ControlOrMeta` modifier key. This key maps to `Meta` on macOS and maps to `Control` on Windows and Linux.
python
Press the common keyboard shortcut Control+S or Meta+S to trigger a "Save" operation.
page.keyboard.press("ControlOrMeta+S")

- New property `httpCredentials.send` in [apiRequest.newContext()](https://playwright.dev/python/docs/api/class-apirequest#api-request-new-context) that allows to either always send the `Authorization` header or only send it in response to `401 Unauthorized`.
- Playwright now supports Chromium, Firefox and WebKit on Ubuntu 24.04.
- v1.45 is the last release to receive WebKit update for macOS 12 Monterey. Please update macOS to keep using the latest WebKit.

Browser Versions
* Chromium 127.0.6533.5
* Mozilla Firefox 127.0
* WebKit 17.4

This version was also tested against the following stable channels:
* Google Chrome 126
* Microsoft Edge 126

1.44.0

New APIs

**Accessibility assertions**
- [expect(locator).to_have_accessible_name()](https://playwright.dev/python/docs/api/class-locatorassertions#locator-assertions-to-have-accessible-name) checks if the element has the specified accessible name:

python
locator = page.get_by_role("button")
expect(locator).to_have_accessible_name("Submit")


- [expect(locator).to_have_accessible_description()](https://playwright.dev/python/docs/api/class-locatorassertions#locator-assertions-to-have-accessible-description) checks if the element has the specified accessible description:

python
locator = page.get_by_role("button")
expect(locator).to_have_accessible_description("Upload a photo")


- [expect(locator).to_have_role()](https://playwright.dev/python/docs/api/class-locatorassertions#locator-assertions-to-have-role) checks if the element has the specified ARIA role:

python
locator = page.get_by_test_id("save-button")
expect(locator).to_have_role("button")


**Locator handler**
- After executing the handler added with [page.add_locator_handler()](https://playwright.dev/python/docs/api/class-page#page-add-locator-handler), Playwright will now wait until the overlay that triggered the handler is not visible anymore. You can opt-out of this behavior with the new `no_wait_after` option.
- You can use new `times` option in [page.add_locator_handler()](https://playwright.dev/python/docs/api/class-page#page-add-locator-handler) to specify maximum number of times the handler should be run.
- The handler in [page.add_locator_handler()](https://playwright.dev/python/docs/api/class-page#page-add-locator-handler) now accepts the locator as argument.
- New [page.remove_locator_handler()](https://playwright.dev/python/docs/api/class-page#page-remove-locator-handler) method for removing previously added locator handlers.

python
locator = page.get_by_text("This interstitial covers the button")
page.add_locator_handler(locator, lambda overlay: overlay.locator("close").click(), times=3, no_wait_after=True)
Run your tests that can be interrupted by the overlay.
...
page.remove_locator_handler(locator)


**Miscellaneous options**
- [expect(page).to_have_url()](https://playwright.dev/python/docs/api/class-pageassertions#page-assertions-to-have-url) now supports `ignore_case` [option](https://playwright.dev/python/docs/api/class-pageassertions#page-assertions-to-have-url-option-ignore-case).

Browser Versions
* Chromium 125.0.6422.14
* Mozilla Firefox 125.0.1
* WebKit 17.4

This version was also tested against the following stable channels:
* Google Chrome 124
* Microsoft Edge 124

Page 1 of 17

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.