Reputation: 1721
I am using Puppeteer scrape a website. Everything is perfect except the script opens chromium browser everytime it runs. Can I stop that? Can I make it run in the background? It is not letting me to do anything because the opening chromim is having the control over all the open applications.
const puppeteer = require('puppeteer');
async function main() {
const productURL = `https://www.example.com`;
const browser = await puppeteer.launch({ headless: false });
const page = await browser.newPage();
await page.setViewport({ width: 1020, height: 768 });
const pageResponse = await page.goto(productURL, { waitUntil: 'networkidle0', timeout: 0 });
// scraping code based on selectors goes here....
await browser.close();
}
Upvotes: 1
Views: 1730
Reputation: 724
You will need to enable headless mode:
const browser = await puppeteer.launch({headless: true});
Headless mode is a browser mode for Chromium that doesn't open a window.
Upvotes: 1