A Node.js library to easily manage and rotate a pool of web browsers, using any of the popular browser automation libraries like Puppeteer, Playwright, or SecretAgent.
const { BrowserPool, PlaywrightPlugin, PuppeteerPlugin } = require('.');
// const playwright = require('playwright');
const browserPool = new BrowserPool({
browserPlugins: [new PlaywrightPlugin(require('playwright').chromium)],
});
console.time('x');
// An asynchronous IIFE (immediately invoked function expression)
// allows us to use the 'await' keyword.
(async () => {
console.timeLog('x', 'before new page');
// // Launches Chromium with Playwright and returns a Playwright Page.
const page1 = await browserPool.newPage();
console.timeLog('x', 'after new page');
// // You can interact with the page as you're used to.
// await page1.goto('https://example.com');
// // When you're done, close the page.
await page1.close();
console.timeLog('x', 'after page close');
// // Opens a second page in the same browser.
// const page2 = await browserPool.newPage();
// When everything's finished, tear down the pool.
await browserPool.destroy();
console.timeLog('x', 'after pool destroy');
console.log(process._getActiveHandles().length);
process.exit();
})();
Fixes #32
Tested manually via: