Browser Pool
No credit card required
Browser Pool
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
-
Go to the Standby tab and copy the Actor URL.
-
Replace
https://
withwss://
: 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
- 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:
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
: eitherdatacenter
orresidential
; 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
orfalse
, passed as option to Playwright. - args: array of arguments to pass to Chromium, e.g.,
["--window-size=1920,1080", "--lang=en-US"]
.
- headless: either
ignoreDefaultArgs
: eithertrue
orfalse
, 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
Actor Metrics
4 monthly users
-
1 star
Created in Aug 2024
Modified 2 months ago