Skip to content

Instantly share code, notes, and snippets.

@jirivrany
Created October 11, 2023 08:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jirivrany/fa16f25d25142a074ab3ca14fe987eee to your computer and use it in GitHub Desktop.
Save jirivrany/fa16f25d25142a074ab3ca14fe987eee to your computer and use it in GitHub Desktop.
Pupeteer - how can I accept cookie consent prompts automatically for any URL?
/*
* Install some "no-cookies extension to your Chrome,
* then copy the extension directory to your Pupeteer dir
*/
const puppeteer = require('puppeteer');
const fs = require('fs/promises');
async function start () {
const pathToExtension = require('path').join(__dirname, 'extensions/3.4.5_0');
const url = 'https://www.example.com/';
const browser = await puppeteer.launch({
headless: false,
args: [
`--disable-extensions-except=${pathToExtension}`,
`--load-extension=${pathToExtension}`,
],
});
const page = await browser.newPage();
await page.goto(url, {
waitUntil: 'networkidle0',
});
await page.screenshot({path: 'screen1.png'});
await browser.close();
}
start();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment