How to emulate specific geolocation coordinates in Puppeteer?

To emulate specific geolocation coordinates in Puppeteer, you can use the setGeolocation method available in the page object. Here's an example of how you can set specific latitude and longitude coordinates in Puppeteer:

const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); // Set the geolocation coordinates to a specific location await page.setGeolocation({ latitude: 37.7749, longitude: -122.4194 }); // Navigate to a website that uses geolocation await page.goto('https://www.example.com'); await browser.close(); })();

In the above example, we used the setGeolocation method to set the geolocation coordinates to San Francisco (latitude: 37.7749, longitude: -122.4194). You can replace these coordinates with any specific location you want to emulate.

Keep in mind that not all websites may support or honor the geolocation coordinates set by Puppeteer. Additionally, if the website requests permission to access the user's location, Puppeteer will not be able to bypass this permission prompt.