DEV Community

Amelia
Amelia

Posted on

How I Debugged Local SEO Rankings Using Puppeteer Location Spoofing

I was trying to debug why my client's bakery in Berlin wasn't showing up in local search results for their own city. Turns out, Google was serving me results based on my IP in Munich. Classic.

So I built a quick script using Puppeteer to spoof my location and see what locals actually see. Here's the core idea:

javascript
const puppeteer = require('puppeteer');

async function spoofLocation(url, lat, lng) {
const browser = await puppeteer.launch({ headless: true });
const page = await browser.newPage();
await page.goto(url);
await page.evaluate((coords) => {
navigator.geolocation.getCurrentPosition = (success) => success({ coords });
}, { latitude: lat, longitude: lng });
// Now search and capture results
const results = await page.evaluate(() => {
return Array.from(document.querySelectorAll('.g')).map(el => el.innerText);
});
console.log(results);
await browser.close();
}

spoofLocation('https://www.google.com', 52.5200, 13.4050); // Berlin

This works for quick checks, but for more robust testing across multiple locations and languages, I've been using a tool that handles this natively without browser automation headaches. It's saved me hours when auditing international SEO setups.

https://serpspur.com

Top comments (0)