I have a nodejs script running on my Macbook 24/7, and every 20 minutes or so it runs Puppeteer to parse the contents of a website. Every two days, the fan gets very loud, and I see Chromium is using lots of CPU and RAM. Is there someway I can fix this?
This is the code I am running:
const options = {
args: [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-dev-shm-usage',
'--disable-accelerated-2d-canvas',
'--no-first-run',
'--no-zygote',
'--single-process',
'--disable-gpu'
],
headless: true
}
const browser = await puppeteer.launch(options);
const page = await browser.newPage();
await page.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36')
await page.setViewport({ width: 1920, height: 1080 });
await page.setRequestInterception(true);
page.on('request', (req) => {
if(req.resourceType() === 'stylesheet' || req.resourceType() === 'font' || req.resourceType() === 'image'){
req.abort();
} else {
req.continue();
}
});
await page.goto(url, { waitUntil: 'networkidle0' });
// ... do stuff
await page.close();
await browser.close();
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment