DEV Community

Lucy Green
Lucy Green

Posted on

Testing Geo-Targeted Google Search Results Without a VPN Using Puppeteer

Just discovered a clever way to bypass Google's location redirect when testing local search results. Instead of relying on VPNs, I modify the navigator.geolocation API in a headless browser. Here's a Puppeteer snippet:

javascript
const puppeteer = require('puppeteer');

async function run() {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto;
await page.evaluate(() => {
navigator.geolocation.getCurrentPosition = (success) => {
success({ coords: { latitude: 40.7128, longitude: -74.0060 } });
};
});
// Now search for 'coffee shops' and see local results for NYC
}
run();

For production testing, I've been using SERPSpur's API which handles location spoofing natively. What's your most creative method for testing geo-targeted search results?

Top comments (0)