Skip to main content

Quick Start

Connect to Browserless using either Puppeteer or Playwright through Chrome's DevTools Protocol (CDP) using websockets. This is the primary and recommended way to connect to Browserless, as it provides a stable and reliable connection.

Follow these steps to get started with Browserless:

  1. Get Your API Token

  2. Install Library

    Choose your preferred automation library and install it:

    npm install puppeteer-core
  3. Run Your First Example

    Here's a complete working example:

    import puppeteer from "puppeteer-core";

    const TOKEN = "YOUR_API_TOKEN_HERE"; // Replace with your actual token

    async function getPageTitle() {
    // Connect to Browserless using WebSocket endpoint
    const browser = await puppeteer.connect({
    browserWSEndpoint: `wss://production-sfo.browserless.io?token=${TOKEN}`,
    });

    const page = await browser.newPage();

    // Navigate to the target website
    await page.goto("https://www.example.com/");

    // Get the page title
    const title = await page.title();
    console.log(`The page's title is: ${title}`);

    // Clean up resources
    await browser.close();
    }

    getPageTitle().catch(console.error);
  4. Expected Output

    After running your script, you should see:

    • Console output: "The page's title is: Example Domain"
    • Successful connection to Browserless
    • Clean browser session termination

Next Steps

Explore these key features to enhance your browser automation: