You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/browser-rendering/platform/playwright.mdx
+38-26Lines changed: 38 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,6 @@ title: Playwright
4
4
description: Learn how to use Playwright with Cloudflare Workers for browser automation. Access Playwright API, manage sessions, and optimize browser rendering.
5
5
sidebar:
6
6
order: 5
7
-
badge: Beta
8
7
---
9
8
10
9
import {
@@ -24,11 +23,17 @@ Our version is open sourced and can be found in [Cloudflare's fork of Playwright
The current version of the Playwright is **v1.54.0**.
26
+
The current version of the Playwright is [**v1.55.0**](https://github.com/cloudflare/playwright/pull/67).
28
27
:::
29
28
30
29
## Use Playwright in a Worker
31
30
31
+
In this [example](https://github.com/cloudflare/playwright/tree/main/packages/playwright-cloudflare/examples/todomvc), you will run Playwright tests in a Cloudflare Worker using the [todomvc](https://demo.playwright.dev/todomvc) application.
32
+
33
+
If you want to skip the steps and get started quickly, select **Deploy to Cloudflare** below.
34
+
35
+
[](https://deploy.workers.cloudflare.com/?url=https://github.com/cloudflare/playwright/tree/main/packages/playwright-cloudflare/examples/todomvc)
36
+
32
37
Make sure you have the [browser binding](/browser-rendering/platform/wrangler/#bindings) configured in your `wrangler.toml` file:
33
38
34
39
<WranglerConfig>
@@ -37,13 +42,10 @@ Make sure you have the [browser binding](/browser-rendering/platform/wrangler/#b
37
42
name = "cloudflare-playwright-example"
38
43
main = "src/index.ts"
39
44
workers_dev = true
40
-
compatibility_flags = ["nodejs_compat_v2"]
41
-
compatibility_date = "2025-03-05"
45
+
compatibility_flags = ["nodejs_compat"]
46
+
compatibility_date = "2025-09-17"
42
47
upload_source_maps = true
43
48
44
-
[dev]
45
-
port = 9000
46
-
47
49
[browser]
48
50
binding = "MYBROWSER"
49
51
```
@@ -61,11 +63,7 @@ Let's look at some examples of how to use Playwright:
61
63
Using browser automation to take screenshots of web pages is a common use case. This script tells the browser to navigate to https://demo.playwright.dev/todomvc, create some items, take a screenshot of the page, and return the image in the response.
One of the most common use cases for using Playwright is software testing. Playwright includes test assertion features in its APIs; refer to [Assertions](https://playwright.dev/docs/test-assertions) in the Playwright documentation for details. Here's an example of a Worker doing `expect()` test assertions of the [todomvc](https://demo.playwright.dev/todomvc) demo page:
Using the above, the browser will stay open for up to 10 minutes, even if inactive.
203
193
194
+
### Session Reuse
195
+
196
+
The best way to improve the performance of your browser rendering Worker is to reuse sessions by keeping the browser open after you've finished with it, and connecting to that session each time you have a new request. Playwright handles [`browser.close`](https://playwright.dev/docs/api/class-browser#browser-close) differently from Puppeteer. In Playwright, if the browser was obtained using a `connect` session, the session will disconnect. If the browser was obtained using a `launch` session, the session will close.
// this will disconnect the browser from the session, but the session will be kept alive
213
+
awaitbrowser.close();
214
+
}
215
+
}
216
+
```
217
+
204
218
### Set a custom user agent
205
219
206
220
To specify a custom user agent in Playwright, set it in the options when creating a new browser context with `browser.newContext()`. All pages subsequently created from this context will use the new user agent. This is useful if the target website serves different content based on the user agent.
@@ -294,13 +308,11 @@ You should also be able to access this information in the dashboard, albeit with
294
308
295
309
The full Playwright API can be found at the [Playwright API documentation](https://playwright.dev/docs/api/class-playwright).
296
310
297
-
Note that `@cloudflare/playwright` is in beta. The following capabilities are not yet fully supported, but we’re actively working on them:
311
+
The following capabilities are not yet fully supported, but we’re actively working on them:
-[Firefox](https://playwright.dev/docs/api/class-playwright#playwright-firefox), [Android](https://playwright.dev/docs/api/class-android) and [Electron](https://playwright.dev/docs/api/class-electron), as well as different versions of Chrome
This is **not an exhaustive list** — expect rapid changes as we work toward broader parity with the original feature set. You can also check [latest test results](https://playwright-full-test-report.pages.dev/) for a granular up to date list of the features that are fully supported.
0 commit comments