Search code examples
javascriptpopupscreenshotheadlessplaywright

GPDR cookie popup in Playwright


Hello I try to make a screenshot with Playwright but I have cookie EU law popup on my screenshots. How can I remove them ?

Here is my browser parameters.

const browser = await playwright.firefox.launch({
   headless: true,
   firefoxUserPrefs: {
    "network.cookie.cookieBehavior": 2
   }
});

But it don't work. Thank for your help.


Solution

  • Use the playwright API to click the element. I'm using the text selector in the example below, but you can use any selector.

    const { webkit } = require('playwright');
    
    (async() => {
        const browser = await webkit.launch({ headless: false });
        const page = await browser.newPage();
        await page.goto('https://npmjs.com');
        await page.click('text=Accept');
        await page.screenshot({ path: 'screenshot.png' });
        await browser.close();
    })();