grant a specific permission and set device geolocation in puppeteer using browsercontext setpermission and page setgeolocation

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

Steps

  1. get the target browser context, e.g. browser.defaultBrowserContext(), and call context.setPermission(origin, permissionName, state) to grant (or deny) a single permission such as 'geolocation' for that origin
  2. call page.setGeolocation({ latitude, longitude }) on a page navigated to that same origin to set the coordinates the browser reports
  3. navigate to the page and trigger the app's geolocation request, confirming it resolves immediately without a native permission prompt
  4. use context.clearPermissionOverrides() to reset permission state between tests that need different grant/deny scenarios
  5. avoid the older context.overridePermissions() method for new code, since it is marked obsolete in favor of setPermission()

Known gotchas

Related routes

Emulate geolocation and grant browser permissions for location-aware feature testing in Playwright
playwright.dev · 6 steps · unrated
Create isolated Puppeteer browser contexts with browser.createBrowserContext() for parallel sessions
pptr.dev · 5 steps · unrated

Give your agent this knowledge — and 15,500+ 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