Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk3 min

How to Override Browser Permissions in Puppeteer

Use Puppeteer’s BrowserContext.setPermission() for new permission overrides. Learn how to grant geolocation, migrate legacy code and clear context overrides.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For new Puppeteer code, set permissions on the page’s BrowserContext with context.setPermission(). The older overridePermissions() method is deprecated. To let a page read its geolocation, grant the geolocation permission for its origin, then set coordinates on the page.

Set a permission on the page’s browser context

Call setPermission() on the BrowserContext that owns the page. Pass the target origin and a permission descriptor with its state. This geolocation example follows the API shape documented in Puppeteer 25.12.0; supported descriptor names can depend on your installed Puppeteer and browser versions.

As an Amazon Associate I earn from qualifying purchases.

const context = browser.defaultBrowserContext();
await context.setPermission('https://example.com', {
  permission: 'geolocation',
  state: 'granted',
});
const page = await context.newPage();

For an isolated context, use that context instead of the default one. Pages expose their owning context through page.browserContext(), which is useful when configuring a page that already exists.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const context = page.browserContext();
await context.setPermission('https://example.com', {
  permission: 'geolocation',
  state: 'granted',
});

The method accepts an origin or '*' and one or more permission descriptor/state objects. Prefer a specific origin when the test only needs to affect one site.

Granting geolocation also requires coordinates

Permission alone does not supply a location. Set the page’s geolocation after granting permission:

await context.setPermission('https://example.com', {
  permission: 'geolocation',
  state: 'granted',
});
await page.setGeolocation({ latitude: 37.7749, longitude: -122.4194 });

Puppeteer’s Page reference advises granting geolocation permission for the page to read the coordinates. Choose coordinates appropriate to the test; the example uses San Francisco.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

How the deprecated method differs

Older examples use overridePermissions() with a list of permission names:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await context.overridePermissions('https://example.com', ['geolocation']);

The current API reference marks this method deprecated in favor of setPermission(). Its documented behavior is also broader: it grants the listed permissions for the origin and automatically denies permissions omitted from the list. Do not treat it as equivalent to setting a single descriptor with setPermission().

Method Status in the current reference Arguments and documented effect
setPermission() Current approach Origin (or '*') and permission descriptor/state object(s); sets permission state for the origin.
overridePermissions() Deprecated Origin and permission-name list; grants listed permissions and automatically denies unlisted ones.

Clear permission overrides after a test

Use clearPermissionOverrides() to clear all permission overrides for a context:

await context.clearPermissionOverrides();

This clears overrides for the entire context, not just one permission or origin. Avoid calling it while other pages or tests sharing that context still depend on an override. Browser contexts isolate storage; the default context cannot be closed, while dedicated contexts can be closed when finished.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers

Common problems and fixes

  • The page still asks for permission: Confirm that you set the permission on the same context that owns the page and used the page’s origin, including the correct scheme and host.
  • Geolocation is granted but no location is available: Granting permission does not set coordinates; call page.setGeolocation() as well.
  • A permission descriptor is rejected or has no effect: Verify the descriptor name against the Puppeteer and browser versions installed in your environment. The API shape does not guarantee every browser version supports every permission descriptor.
  • A later test unexpectedly loses its setting: Check whether another test called clearPermissionOverrides() on the shared context; it clears all overrides there.
  • Legacy code behaves differently after migration: Review omitted permissions. The deprecated method automatically denies permissions not listed, a behavior not to assume when replacing it with individual setPermission() calls.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If the goal is simply to capture a website rather than test its browser permission behavior, ScreenshotNeo provides a screenshot API and MCP server. For example, this cURL request captures a page as WebP:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo API documentation for request options. Cookie banners are accepted and removed, along with known consent platforms, newsletter popups and chat widgets, before capture; those cleanup steps can be turned off. Bot checks, blank pages, timeouts, failed loads and cache hits are not billed, with response headers indicating the page verdict and billing status. Its MCP server includes tools for AI agents to take screenshots, get page information and capture PDFs. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for the free plan.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.