bautaDocs

Connecting Puppeteer

Connect Puppeteer to a persona through the gateway, or launch one from the Node.js package.

Puppeteer connects to a persona's WebSocket endpoint on the gateway. Only the connect call changes; the rest of your code stays as it is.

Start the gateway

With bauta installed and set up (Getting Started), make a persona and start the gateway:

bauta geo update                              # the database that places a proxy's exit
bauta persona new shop --from win-intel
bauta serve

Each persona is then an endpoint of its own: ws://127.0.0.1:9222/persona/<name>.

Connect

const puppeteer = require("puppeteer-core");

const browser = await puppeteer.connect({ browserWSEndpoint: "ws://127.0.0.1:9222/persona/shop" });
const page = await browser.newPage();
await page.goto("https://example.com");
console.log(await page.evaluate(() => navigator.platform)); // Win32
await browser.disconnect();

A client sees only its own persona's pages, as if the browser were its own. A persona keeps its own profile, so its cookies and storage are there on the next connection. Its browser closes 30 seconds after its last client leaves; bauta serve --idle changes that.

Launch from the Node.js package

bautabrowser/puppeteer reaches the gateway on this machine, or starts it, makes the persona and connects:

npm install bautabrowser puppeteer-core
const { launch } = require("bautabrowser/puppeteer");

const browser = await launch({ proxy: "http://user:pass@host:port", humanize: true });
const page = await browser.newPage();
await page.goto("https://example.com");
await browser.disconnect();

It takes the same options as the package's Playwright launch() (Python and Node.js packages). A launch without name gets a fresh identity that keeps nothing. To keep a persona's cookies and storage between launches, name it and set ephemeral to false:

const browser = await launch({ name: "shop", ephemeral: false });

Every bundled persona answers navigator.webdriver with false, so an automated launch does not announce itself.

Clicks and user activation

A script you run is the page's, not a person's. page.evaluate and the like give the page no user activation: a person's click or key, which Chrome requires to open a popup, go fullscreen or write the clipboard. With it, a page would see an activation that no input came before. For what needs a person, click:

await page.click("#open");

A persona with humanize makes clicks and typing move as a hand does.

The persona's identity is fixed

A client that sets its own User-Agent, viewport, locale or timezone is answered as if it had, but the page keeps the persona's.

Next

On this page