-
-
Save anonymous/c3d9b0d51127ea0bd396432075b2990a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const genericPool = require('generic-pool'); | |
const puppeteer = require('puppeteer'); | |
// puppeteer.launch will return a promise to resolve with a browser instance | |
const browserPromise = puppeteer.launch(); | |
const factory = { | |
create: async function() { | |
// reuse the same browser instance to create new pages | |
const browser = await browserPromise(); | |
const page = await browser.newPage(); | |
await page.setViewport({ width: 800, height: 420 }); | |
return page; | |
}, | |
destroy: function(puppeteer) { | |
puppeteer.close(); | |
}, | |
}; | |
const browserPagePool = genericPool.createPool(factory, { | |
max: 10, | |
min: 2, | |
maxWaitingClients: 50, | |
}); | |
module.exports = browserPagePool; |
This doesn't pool the pages against a single browser. It just keeps on opening new browsers for each request since create() is called for each new request
This doesn't pool the pages against a single browser. It just keeps on opening new browsers for each request since create() is called for each new request
+1. Code might even crash the server by spawning unlimited browsers over time.
This doesn't pool the pages against a single browser. It just keeps on opening new browsers for each request since create() is called for each new request
+1. Code might even crash the server by spawning unlimited browsers over time.
lol
(f=>f(f))(async f=>f(f)&&f(f));
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This
const browserPromise = puppeteer.launch();
causes an out of memory allocation error. You need to await the puppeteer.launch() instead