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 setPermission(). The older overridePermissions() method is deprecated. To let a page read test geolocation, grant its origin the geolocation permission and set coordinates separately.

Grant a permission with the current Puppeteer API

Call setPermission() on the browser context that owns the page. This example grants geolocation to https://example.com before creating a page in the default context:

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

The current reference documents an origin argument (or '*') and one or more permission descriptor/state objects. Descriptor names supported can depend on the installed Puppeteer and browser versions, so verify the names for your environment. See the BrowserContext.setPermission() reference.

Use the context that owns the page

Permissions are set on a BrowserContext and scoped to an origin. If a page was created in a dedicated context, set the permission on that same context; changing another context will not configure the page under test. You can get a page’s context with page.browserContext(). The default context is available through browser.defaultBrowserContext(); Puppeteer also documents browser.setPermission() as a shortcut for the default context. Contexts isolate storage, and the default context cannot be closed. See the BrowserContext reference.

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

Set geolocation permission and coordinates

Granting permission and choosing coordinates are separate steps. After granting permission for the page’s origin, set the page’s geolocation:

await context.setPermission('https://example.com', {
  permission: 'geolocation',
  state: 'granted',
});

const page = await context.newPage();
await page.setGeolocation({ latitude: 37.7749, longitude: -122.4194 });
await page.goto('https://example.com');

The coordinate values here are an example, not a required location. Puppeteer’s Page reference advises granting permission for a page to read geolocation set with setGeolocation(). Check the Page.setGeolocation() reference for the installed version’s details.

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 an array of permission names. Puppeteer marks it deprecated in favor of setPermission() in the current API reference.

await context.overridePermissions('https://example.com', ['geolocation']);

The old method’s documented behavior is broader than setting one descriptor: it grants the listed permissions for the origin and automatically denies permissions omitted from the list. Do not assume that replacing it with a single setPermission() call preserves that behavior. For new code, use the current API and explicitly configure the permissions your test requires. See the overridePermissions() reference and setPermission() reference.

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

Clear permission overrides after a test

To remove permission overrides for a context, call:

await context.clearPermissionOverrides();

This clears all permission overrides for that context, not just the one made by the current test. If multiple pages or tests share a context, clear overrides only when doing so will not disrupt their setup. See the clearPermissionOverrides() reference.

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

Troubleshooting permission tests

  • The page still cannot access a permission: Confirm the origin passed to setPermission() matches the page’s origin, and that you configured the page’s own context.
  • Geolocation is unavailable or incorrect: Grant geolocation permission and set coordinates with page.setGeolocation(); one does not substitute for the other.
  • A permission descriptor is rejected: Check that the descriptor is supported by the browser version used by your installed Puppeteer. The API shape alone does not guarantee every browser accepts every descriptor.
  • Another test loses permissions: Check for a call to clearPermissionOverrides() on a shared context; it clears all overrides for that context.
  • Legacy code behaves differently after migration: The deprecated array method denies omitted permissions automatically. Review any test that relied on those implicit denials before changing to per-permission setPermission() calls.

Or skip the browser setup:

If your goal is a screenshot rather than testing browser permission behavior, ScreenshotNeo provides a website screenshot API and MCP server. A single GET request can return an image or PDF. For example, save a WebP screenshot of a URL with cURL:

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 documentation for request options. It accepts cookie or consent banners like a visitor and removes 60+ known consent platforms, newsletter popups and chat widgets before capture; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads and cache hits cost nothing, and responses identify the page verdict and billing status in headers. Its MCP server offers take_screenshot, get_page_info and capture_pdf for AI agents. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 shots.

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

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Frequently Asked Questions

Can I grant more than one permission with setPermission()?

The API accepts one or more permission descriptor/state objects. Which descriptors are supported depends on the installed Puppeteer and browser versions.

Does setPermission() configure geolocation coordinates?

No. It grants the permission; set coordinates separately with the page’s setGeolocation() method.

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.

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