Skip to content

Instantly share code, notes, and snippets.

@ankitsadariya
Created February 2, 2021 07:07
Show Gist options
  • Save ankitsadariya/fd8607933c9313e77f62056b4159e1ec to your computer and use it in GitHub Desktop.
Save ankitsadariya/fd8607933c9313e77f62056b4159e1ec to your computer and use it in GitHub Desktop.
set geolocation for website using puppeteer
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({ devtools: true });
const page = await browser.newPage();
// Grants permission for changing geolocation
const context = browser.defaultBrowserContext();
await context.overridePermissions('https://www.google.com/', ['geolocation']);
await page.goto('https://www.google.com/');
await page.waitForSelector('title');
// Changes to the north pole's location
await page.setGeolocation({ latitude: 90, longitude: 0 });
//await browser.close();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment