Open

The following example demonstrates how to request a browser instance, navigate to a webpage, and close the browser:

const rp = await browserService.open();
console.log('Browser opened');

const browser = await puppeteer.connect({
  browserWSEndpoint: rp.address,
  defaultViewport: null,
  ignoreHTTPSErrors: true,
  slowMo: 0
});

const pages = await browser.pages();
const page = pages[0];
await page.goto('https://cloudbrowser.ai');

Full example

This code initializes a Puppeteer browser instance using a remote service and navigates to a specific webpage. First, it opens a remote browser session via browserService.open() and logs that the browser has been opened. Then, it connects Puppeteer to the remote browser using the WebSocket endpoint from the session (rp.address) with specific options, such as disabling viewport restrictions and ignoring HTTPS errors. It retrieves all open pages within the browser, selects the first one, and navigates it to the URL https://cloudbrowser.ai.

Open (with parameters)

The following example demonstrates how to request a browser instance with advanced configuration, including custom browser settings, proxy, and a timeout for keeping the browser open.

  • Label: Set a custom label for the browser instance.

  • Browser: Choose the browser type (e.g., Chromium or Chrome).

  • KeepOpen: Set the timeout in seconds for how long the browser should remain open without a Puppeteer connection.

  • Proxy: Configure proxy settings (host, port, username, password).

const rp = await browserService.open({
    label: "MyCustomBrowser",
    //Chromium is supported but we recommend Chrome for best stealth
    browser: SupportedBrowser.CHROMIUM,
    keepOpen: 10 * 60, //This browser will close after 10 minutes without any Puppeteer connected.
    proxy: {
        host: "IP.0.0.0.1",
        port: "3000",
        password: "password",
        username: "username",
    },
});

Full example

Last updated