Playwright
playwright
is a new cross-browser library written by Microsoft to aide in cross-browser testing and development. We support playwright
out of the box via their pw.chromium.connect
method. As of now, we only support their chromium
option, but we're working on other browsers as well.
browserless supports two different methods for connecting via playwright, each with its own benefits and drawbacks. In short, there are two API methods that we support:
playwright.chromium.connect(wsEndpoint: string)
The standard connect
method uses playwright's built-in browser-server to handle the connection. This, generally, is a faster and more fully-featured method since it supports most of the playwright parameters (such as using a proxy and more). However, since this requires the usage of playwright in our implementation, things like ad-blocking and stealth aren't supported. In order to utilize those, you'll need to see our integration with connectOverCDP
.
NOTE: If you are using a usage-based or cloud unit-based API key, your playwright version must match one of our supported versions, read more info on playwright compatible versions.
Take a screenshot in playwright
const pw = require('playwright');
(async () => {
const browser = await pw.chromium.connect(
'wss://chrome.browserless.io/playwright?token=YOUR-API-TOKEN'
);
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://www.example.com/');
await page.screenshot({ path: 'example.png' });
await browser.close();
})();
playwright.chromium.connectOverCDP(wsEndpoint: string)
The "connectOverCDP" endpoint allows playwright to connect through Chrome's DevTools Protocol. While this is more functionally similar to how puppeteer operates, it does come with a slight performance hit since sessions are more "chatty" over the network versus playwright's connect
. Because it's similar to puppeteer, you can use one of our built-in helpers like ad-blocking or stealth to your session. If you're wanting to use playwright's proxy helper then you'll need to use the connect
method instead.
Take a screenshot in playwright
const pw = require('playwright');
(async () => {
const browser = await pw.chromium.connectOverCDP(
'wss://chrome.browserless.io?token=YOUR-API-TOKEN'
);
const context = await browser.newContext();
const page = await context.newPage();
await page.goto('https://www.example.com/');
await page.screenshot({ path: 'example.png' });
await browser.close();
})();
You can use all the same APIs and helper functions directly with browserless, and begin to scale out your playwright
applications and tests today.
What's more, is that you can use all of the same launch arguments for puppeteer, directly with playwright
and connectOverCDP
!