## TL;DR

Clipboard in e2e tests needs two things: the browser context granted `clipboard-read` and `clipboard-write` permissions, and a secure context (the loopback address or https) since the Clipboard API refuses insecure origins. Grant the permissions in the context setup, perform the copy action in the app, then read the clipboard from the test and assert the value. Headless quirks exist, so run headed at least once to confirm the flow works like a real user sees it.

## The query

```text
how to test clipboard permissions in e2e
```

## Use this when

- Testing copy buttons, share links, or paste flows.
- Clipboard tests fail with permission errors.

## Not for

- Unit-testing a copy utility; mock the clipboard there.
- Native mobile clipboard behavior.

## Steps

1. In context setup, grant `clipboard-read` and `clipboard-write` permissions. Expected output: the context starts with clipboard access.
2. Serve the app over a secure origin (https, or the loopback address) so the Clipboard API is available. Expected output: `navigator.clipboard` exists in the page.
3. Perform the copy action as a user would (click the copy button). Expected output: the app reports a successful copy.
4. Read the clipboard from the test context and assert the value matches. Expected output: the clipboard holds exactly the expected text.
5. Run once in headed mode to confirm headless did not hide a real problem. Expected output: headed and headless agree.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_vg6W7IQ49z2cpvbrTQGklQ
