I have problem with EventEmitter memory leak detected
I have function that starts the browser like this
async function startBrowser() {
const revisionInfo = await browserFetcher.download("901912");
const browser = await puppeteer.launch({
executablePath: revisionInfo.executablePath,
args: [
"--no-sandbox",
"--disable-gpu",
"--disable-dev-shm-usage",
"--disable-setuid-sandbox",
"--no-first-run",
"--no-zygote",
"--single-process",
],
});
const page = await browser.newPage();
return { browser, page };
}
One of my functions maps through number of items like
const work = (stuff) => {
const workTodo = stuff.map(item = {
setTimeout(() => {
anotherFunction(some params)
}, some time variable all different seconds
}
await Promise.all(workTodo);
}
and in the anotherFunction()
anotherFunction(someParams) {
const { browser, page } = await startBrowser();
try {
await browser.newPage();
await page.goto('stuff');
await page.waitForSelector('stuff');
await page.click('stuff');
await page.close();
await browser.close();
} catch (error) {
console.log('error', error);
return
}
The logic in anotherFunction() works about 70-80 % of the time, but sometimes it gets timeout exceeded at waitForSelector calls and sometimes I get memory leak errors.
Am I creating too many browsers ? and not closing properly?
Can someone who knows puppeteer tell me what Im doing wrong?