Puppeteer is a popular Node.js library for browser automation that integrates seamlessly with Hyperbrowser sessions. This guide shows you how to connect Puppeteer to your cloud browsers. Python has an unofficial library called pyppeteer, however, it is unmaintained and is out of sync with the main Puppeteer library so we recommend using playwright-python instead.
Installation
npm install @hyperbrowser/sdk puppeteer-core dotenv
For Node.js, use puppeteer-core instead of puppeteer since Hyperbrowser provides the
browser. This saves disk space and installation time.
Basic Connection
Connect Puppeteer to a Hyperbrowser session:
import { Hyperbrowser } from "@hyperbrowser/sdk";
import { connect } from "puppeteer-core";
import { config } from "dotenv";
config();
const client = new Hyperbrowser({
  apiKey: process.env.HYPERBROWSER_API_KEY,
});
async function main() {
  // Create session
  const session = await client.sessions.create();
  try {
    // Connect Puppeteer
    const browser = await connect({
      browserWSEndpoint: session.wsEndpoint,
      defaultViewport: null,
    });
    const defaultContext = browser.defaultBrowserContext();
    // Get or create a page
    const pages = await defaultContext.pages();
    const page = pages[0];
    // Navigate and interact
    await page.goto("https://example.com");
    console.log("Title:", await page.title());
  } catch (err) {
    console.error("Encountered error:", err);
  } finally {
    // Clean up
    await client.sessions.stop(session.id);
  }
}
main().catch(console.error);
Next Steps