Does your company rely on browser automation or web scraping? We have a wild offer for our early customers! Read more →

Playwright Guide

Playwright is one of the most popular automation libraries created by Microsoft, with over 65k stars on Github.

Getting Started with a New Project

To begin, install Playwright

1
npm install playwright-core

Use chromium.connectOverCDP method to connect to your remote browser. Here's an example.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import { chromium } from 'playwright-core'

(async () => {
  const rebrowserParams = {
    apiKey: '<YOUR_API_KEY>',
  }
  const browser = await chromium.connectOverCDP(`wss://ws.rebrowser.net/?${new URLSearchParams(rebrowserParams)}`)
  const context = browser.contexts()[0]
  const page = await context.newPage()
  await page.goto('https://rebrowser.net')
  await page.close()

  await (await browser.newBrowserCDPSession()).send('Rebrowser.finishRun')
  await browser.close()
})().catch((error) => console.error(error.message))

Now you can visit Dashboard / Runs and see the results of your run.

Make sure to replace YOUR_API_KEY with your actual API key.

You can read more about all parameters to start a new run on Documentation / API / startRun.

Updating Your Existing Code

If you have an existing codebase working with Playwright, it's super easy to modify it to start leveraging a remote browser instead.

Without Rebrowser

1
2
3
4
5
6
import playwright from 'playwright'

const browser = await playwright.chromium.launch()
const context = await browser.newContext()
const page = await context.newPage()
// ...

With Rebrowser

1
2
3
4
5
6
7
8
9
import { chromium } from 'playwright-core'

const rebrowserParams = {
  apiKey: 'YOUR_API_KEY',
}
const browser = await chromium.connectOverCDP(`wss://ws.rebrowser.net/?${new URLSearchParams(rebrowserParams)}`)
const context = browser.contexts()[0]
const page = await browser.newPage()
// ...

Fix The Leaks!

We highly encourage every customer to do some extra steps to fix all automation leaks.

You can read more on this page: Documentation / Stealth & Automation Detection

How about Playwright Python, Java, .NET?

All other programming language versions of Playwright support connectOverCDP. You just need to change one line of code to start using Rebrowser.

Get more info in Playwright docs: Python, Java, .NET.