[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to main content
Version: v2

Playwright

Playwright is a cross-browser library written by Microsoft to aide in cross-browser testing and development. This page helps you get started quickly connecting remotely to browserless instead of launching browsers locally. You can find more detailed documentation on playwright's documentation site.

We (officially) support Playwright in several languages, as well as using Playwright with an unlocked endpoint via our BrowserQL.

warning

To avoid errors with no apparent reason, please make sure your playwright version is compatible with one of these versions.

We support playwright for Javascript out of the box for all their supported browsers.

Using the Playwright Protocol

The standard connect method uses Playwright's built-in browser-server protocol 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 servers, your client's Playwright version should match ours.

Take a screenshot in Playwright with Firefox
import playwright from "playwright-core";

const pwEndpoint = `wss://production-sfo.browserless.io/firefox/playwright?token=YOUR_API_TOKEN_HERE`;
const browser = await playwright.firefox.connect(pwEndpoint);
const context = await browser.newContext();
const page = await context.newPage();

await page.goto("https://www.nexcess.net/web-tools/browser-information/");
await new Promise((resolve) => setTimeout(resolve, 50000));
await page.screenshot({
path: `firefox.png`,
});

await browser.close();

Similarly, if you need to use another browser, just make sure the Playwright Browser object matches the endpoint.

Using the Chrome DevTools Protocol

The connectOverCDP method 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. Furthermore, you can only use the Chrome for these connections.

Take a screenshot in Playwright
import playwright from "playwright";

const browser = await playwright.chromium.connectOverCDP(
"wss://production-sfo.browserless.io?token=YOUR_API_TOKEN_HERE"
);
const context = await browser.newContext();
const page = await context.newPage();

await page.goto("https://www.example.com/");
await page.screenshot({ path: "cdp.png" });

await browser.close();