Apify Discord Mirror

Updated 2 months ago

How to close Puppeteer browser mid-run while continuing actor execution in crawlee?

At a glance

The community member is using PuppeteerCrawler for web scraping and is able to extract data from network requests. However, they no longer need the Puppeteer browser instance after extracting the data, but they want the script to continue running in the background to process and format the extracted data. The community member is asking if there is a way to close the Puppeteer browser mid-run while keeping the script alive to handle the data.

In the comments, another community member suggests using await page.browser().close() to explicitly close the Puppeteer browser instance. The other community members confirm that the script can continue executing further processing after the browser is closed.

Hi everyone,

I’m using PuppeteerCrawler for scraping because it unblocks websites effectively and allows JavaScript execution. However, I’m facing an issue:

After accessing a website, I extract the required data from network requests (e.g., HTML) and parse it later with cheerio.
At this point, I no longer need the browser, but I still want the Actor to continue running in the background to process and format the extracted data.
Is there a way to close the Puppeteer browser mid-run to free up resources while keeping the Actor alive to handle the data?

Any guidance or examples would be greatly appreciated!

Thanks!
E
S
4 comments
first, using await page.browser().close() explicitly closes the Puppeteer browser instance.
@Exp Hi, that's it? Nothing else? it won't affect Actor in any way?
The script can continues executing further processing after the browser is closed.
Add a reply
Sign up and join the conversation on Discord