Browser Pool avatar

Browser Pool

Try for free

No credit card required

View all Actors
Browser Pool

Browser Pool

marco.gullo/browser-pool
Try for free

No credit card required

A Standby Actor for providing a pool of on-demand browsers, accessible through CDP.

What is Browser Pool?

Browser Pool is a tool that leverages the Apify platform and provides you with headless browsers for building AI agents.

Why using Browser Pool?

Because it can rely on well tested features by Apify, such as proxies, which help to circumvent obstacles and let you concentrate on developing the online automation.

How to use Browser Pool

  1. Go to the Standby tab and copy the Actor URL.

  2. Replace https:// with wss://: you now have the URL for connecting your Playwright session to Apify through CDP, which looks something like this:

wss://marco-gullo--browser-pool.apify.actor?token=$TOKEN
  1. Finally, you can use the URL with Playwright. Let's say you want to generate and download the emoji of a smiling rocket on emojikitchen.dev:
1import fs from 'fs;
2import { chromium } from 'playwright';
3
4console.log('Connecting to a remote browser on the Apify platform');
5const wsEndpoint = 'wss://marco-gullo--browser-pool.apify.actor?token=$TOKEN&other_params...';
6const browser = await chromium.connect(wsEndpoint);
7
8console.log('Browser connection established, creating context');
9const context = await browser.newContext({ viewport: { height: 1000, width: 1600 } });
10
11console.log('Opening new page');
12const page = await context.newPage();
13
14const timeout = 60_000;
15console.log(`Going to: ${url}. Timeout = ${timeout}ms`);
16await page.goto(url, { timeout });
17
18console.log('Selecting emojis');
19await page.getByRole('img', { name: 'rocket' }).first().click();
20await page.getByRole('img', { name: 'smile', exact: true }).nth(1).click();
21
22console.log('Saving screenshot');
23const screenshot = await page.getByRole('img', { name: 'rocket-smile' }).screenshot();
24fs.writeFileSync('rocket-smile.png', screenshot);
25
26console.log('Closing the browser');
27await context.close();
28await browser.close();

This code is executed locally, and in the end you will have this nice picture on your computer:

Rocket Smile

Nevertheless, the browser runs on the Apify platform, so there is no need for you to install Chromium.
Moreover, you can mock your location or try to circumvent blocks using Apify's proxies. To do so, you need to use search parameters: see below.

Search parameters

You can customize your session using search parameters. They are designed to be compatible with browserless.io:

  • proxy: either datacenter or residential; selects the corresponding default proxy groups.
  • proxyGroups: stringified JSON of an array of Apify proxy groups, e.g., ["RESIDENTIAL5"].
  • proxyCountry: ISO 3166 country code.
  • launch: stringified JSON containing the following properties:
    • headless: either true or false, passed as option to Playwright.
    • args: array of arguments to pass to Chromium, e.g., ["--window-size=1920,1080", "--lang=en-US"].
  • ignoreDefaultArgs: either true or false, if true only uses the passed browser arguments.
  • timeout: maximum allowed time to spawn the browser server, in milliseconds.
  • ttl: time to live, in milliseconds, of the browser session after the socket has been closed.

For example, if you wanted to use Apify's residential proxies from the United States, your URL would look like this:

wss://marco-gullo--browser-pool.apify.actor?token=$TOKEN&proxy=residential&proxyCountry=us
Developer
Maintained by Community
Actor metrics
  • 3 monthly users
  • 1 star
  • 100.0% runs succeeded
  • Created in Aug 2024
  • Modified 20 days ago
Categories