Search code examples
geolocationplaywrightplaywright-java

Configure Playwright to avoid browser notifications (such as "this page wants to know your location")


I'm using Playwright to analyze data from a remote site. However, at the first call to

page.goto(URL)    # Initial URL

the server pops up a panel, as far as I can tell before any Javascript runs:

enter image description here

So far, the only solution I've found is to manually dismiss it. This is less than ideal since it means I can't run Playwright in headless mode.

Any suggestions?


Solution

  • You can use the launchOption configuration to disable the prompt.

    module.exports = {
    //other playwright related configuration
      use: {
            // Browser options
            browserName: 'chromium',
            channel: 'chrome',
            headless: false,
            launchOptions: { args: ['--deny-permission-prompts'] }, //use this option to disable the prompt
           
            actionTimeout: 30 * 1000,
            navigationTimeout: 90 * 1000,
        },
    }
    `