Playwright automation cant bypass location popup

Viewed 1090

I'm attempting to use Playwright (https://github.com/microsoft/playwright) and I'm met by the location popup when I try to test the library. Is there a way to bypass this popup or at least click either "Block" or "Allow"? I've tried using the Page.on("popup") event but it isn't quite working the way I was expecting it to.

popup

2 Answers

You have to use the grantPermissions function to grant geolocation for the site.

await context.grantPermissions(['geolocation'], { origin: 'https://www.bestbuy.com' });

This is how I grant geo localization on my script


const { chromium } = require("playwright");

(async () => {
  // const browser = await chromium.launch({ headless: false});
  const browser = await chromium.launch();
  const context = await browser.newContext();
  await context.grantPermissions(['geolocation'], { origin: 'yourPage.com' });
  const page = await context.newPage();
  await page.goto('yourPage.com');
  browser.close();
})();

here is the documentation playwright.dev

Related