Speed up your automation with parallelization
Leverage multiple browser instances in parallel with a simple task queue.
Some complex automation requires processing multiple pages and actions without resulting in an exponential duration. For example, a backup automation tool must access and back up hundreds of pages reliably and efficiently.
Using multiple pages or contexts for parallelism will result in issues with Browserbase’s persistent context. Instead, we recommend leveraging multiple browser instances as a pool to process actions on numerous pages in parallel.
Enable parallelism with a pool of Browser instances
Let’s walk through the code of our example script processing hundreds of Wikipedia pages efficiently:
The processBrowserbaseTasks() utility
The processBrowserbaseTasks()
utility creates 5 Browserbase Sessions and reuses the available pages between tasks:
Creating a task to fetch each Wikipedia page
Let’s create a function that will be called with a page
for each Wikipedia URL and return the url
, content
tuple:
Passing the tasks to `processBrowserbaseTasks()` and printing the results
Run the automation
Let’s now run our Wikipedia automation; you will notice that pages are processed by a group of 5:
Find the complete example on GitHub
Clone this GitHub repo to get started with a Playwright parallelism setup
Was this page helpful?