Granting permissions

Prev Next

Some web features, such as clipboard access or browser notifications, require user permission. If your test involves one of these features, you'll need to grant permission in advance to avoid a popup like this:

How to set it up

Before running the step that triggers the browser’s permission request, pre-approve the permission using a Playwright code step. You can find the full list of supported permissions in Playwright’s documentation.

Here’s an example for granting clipboard access (read and write):

await context.grantPermissions(["clipboard-read", "clipboard-write"]);

This should be placed before the step that uses the permission. Granting the permission after the request may not work in all cases.

You can grant multiple permissions at once by listing them in the array as shown above.

Granting permissions to a specific website

By default, permissions will be granted to all websites during the test.

If you only want to allow access on a specific domain, use the origin option:

await context.grantPermissions(
  ["clipboard-read", "clipboard-write"],
  { origin: "https://example.com" }
);