Created
October 11, 2023 08:22
-
-
Save jirivrany/fa16f25d25142a074ab3ca14fe987eee to your computer and use it in GitHub Desktop.
Pupeteer - how can I accept cookie consent prompts automatically for any URL?
This file contains hidden or 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
/* | |
* 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