Emulate geolocation and grant browser permissions for location-aware feature testing in Playwright

domain: playwright.dev · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Create a browser context with geolocation and permissions: await browser.newContext({ geolocation: { latitude: 51.5074, longitude: -0.1278, accuracy: 100 }, permissions: ['geolocation'] })
  2. Navigate to the page under test; calls to navigator.geolocation.getCurrentPosition() will return the emulated coordinates
  3. To update location mid-test, call await context.setGeolocation({ latitude: 48.8566, longitude: 2.3522 })
  4. To test the permission-denied flow, create the context without granting 'geolocation' and verify the app handles the error state correctly
  5. For additional permissions such as notifications or camera, add them to the permissions array: ['geolocation', 'notifications']
  6. Confirm the emulated coordinates are visible in the page by evaluating navigator.geolocation as a page function if needed

Known gotchas

Related routes

Run multi-user scenarios in a single Playwright test using parallel browser contexts
playwright.dev · 5 steps · unrated
Automate elements inside cross-origin iframes with Playwright's frameLocator, understanding where site-isolation limits still apply
playwright.dev · 5 steps · unrated
Intercept, inspect, and mock network requests in Playwright tests
playwright.dev · 5 steps · unrated

Give your agent this knowledge — and 15,600+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans