Puppeteer Guide
Puppeteer is one of the most popular automation libraries, with over 85k stars on Github.
Getting Started with a New Project
To begin, install Puppeteer
1npm install puppeteer-core
Use puppeteer.connect
method to connect to your remote browser. Here's an example.
1import puppeteer from 'puppeteer-core';
2
3(async () => {
4 const rebrowserParams = {
5 apiKey: 'YOUR_API_KEY',
6 }
7 const browser = await puppeteer.connect({
8 browserWSEndpoint: `wss://ws.rebrowser.net/?${new URLSearchParams(rebrowserParams)}`,
9 })
10
11 const page = await browser.newPage()
12 await page.goto('https://rebrowser.net')
13 await page.close()
14
15 await browser.close()
16})().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 Puppeteer, it's super easy to modify it to start leveraging a remote browser instead.
Without Rebrowser
1import puppeteer from 'puppeteer'
2
3const browser = await puppeteer.launch()
4const page = await browser.newPage()
5// ...
With Rebrowser
1import puppeteer from 'puppeteer'
2
3const rebrowserParams = {
4 apiKey: 'YOUR_API_KEY',
5}
6const browser = await puppeteer.connect({
7 browserWSEndpoint: `wss://ws.rebrowser.net/?${new URLSearchParams(rebrowserParams)}`,
8})
9const page = await browser.newPage()
10// ...
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