Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitchesiTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more
To test text copied by a web app, trigger its real Copy action and read the result with navigator.clipboard.readText() in the page. In Playwright Test, grant clipboard permissions for the test context when the browser supports them, then wait for the expected text rather than adding a fixed delay.
A minimal Playwright Test example
This example shows the basic pattern for a browser that supports the requested permissions. Replace the URL, button name, and expected value with those used by your app.
import { test, expect } from '@playwright/test';
test.use({ permissions: ['clipboard-read', 'clipboard-write'] });
test('copies the selected value', async ({ page }) => {
await page.goto('https://app.example.test');
await page.getByRole('button', { name: 'Copy' }).click();
await expect.poll(() => page.evaluate(() => navigator.clipboard.readText()))
.toBe('expected text');
});
The click exercises the app’s user-facing copy behavior; the assertion reads the clipboard through the page’s browser context. readText() is asynchronous and resolves to a string when access succeeds. It can reject when access is denied, so let the Playwright assertion report a failure rather than swallowing the error. MDN’s Clipboard API overview describes the browser API and its access model.
Set up permissions without repeating boilerplate
For a file where every test needs clipboard access
Use test.use() near the top of the test file, as in the example. This keeps shared setup short. The permissions are applied to the test context, so use this only where the tests actually need clipboard access.
#1 Best Overall
For an isolated context or a reusable helper
When you create a context directly, grant permissions on that context and scope them to the app origin when practical. Then create a page from that context and close the context after the test or helper finishes.
const context = await browser.newContext();
await context.grantPermissions(
['clipboard-read', 'clipboard-write'],
{ origin: 'https://app.example.test' }
);
const page = await context.newPage();
try {
// Navigate, perform the copy action, and assert the clipboard text.
} finally {
await context.close();
}
Use the exact origin the page runs on, including its scheme and host. An origin-scoped grant is narrower than granting a permission without an origin filter. For repeated use, put the setup in a fixture or helper if that removes real duplication, while keeping browser-specific permission choices visible. Playwright’s BrowserContext API accepts an optional origin for permission grants.
Rank #2
Wait for the clipboard value, not an arbitrary delay
Some apps write to the clipboard asynchronously after the button click. expect.poll() repeatedly evaluates the read and succeeds when it returns the expected value. If the app writes synchronously, a direct awaited read and comparison can be enough; polling is useful when the timing depends on the app’s copy flow.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
A fixed sleep does not establish that the clipboard contains the right text: it may be unnecessarily long on a fast run or too short on a slow one. Wait for the observed result instead. Clipboard access also requires a secure context; use HTTPS for a deployed test target. If access is denied, the read may reject rather than return the expected string. MDN’s readText() reference documents the asynchronous read and its access constraints.
Choose a permission strategy that matches the browser
There are two broad ways to handle reads: grant clipboard permissions in the Playwright context, or exercise the browser’s user-activation and paste-prompt behavior. A permission grant can simplify an app-behavior assertion in browsers that support it; relying on activation and prompts is closer to the browser’s permission UX but can require the test to model a real gesture and respond to browser prompts.
These are not interchangeable recipes for every engine. Playwright warns in its BrowserContext documentation: “Supported permissions differ between browsers, and even between different versions of the same browser. Any permission may stop working after an update.” Verify the permissions against the Playwright and browser versions pinned in your CI environment. Playwright’s permission documentation lists clipboard permissions as supported by some browsers, not as a universal guarantee.
Rank #4
| Approach | What it tests | Important constraint |
|---|---|---|
| Grant permissions in the Playwright context | App copy behavior followed by a browser-side clipboard read | Permission availability varies by browser and version; origin scoping is available through the context API. |
| Rely on user activation and browser prompt behavior | Clipboard access under the browser’s activation and prompt rules | Reads may need a genuine user gesture and handling of the browser’s prompt behavior. |
Account for Chromium, Firefox, and WebKit differences
Chromium
Chromium uses clipboard permission controls, but activation requirements can change. The Playwright-maintained clipboard test notes that Chromium 153 and later requires a real input event to activate the page before reading. Treat this as a version-specific implementation detail, not a permanent rule for all Chromium releases. If a permission grant alone stops working, check the source behavior for the exact browser version you run. Playwright’s maintained clipboard test documents its current setup.
Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutePC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Firefox
MDN says Firefox does not support the clipboard-read and clipboard-write permissions in the same way Chromium does; reads that would otherwise be disallowed rely on transient activation and a paste prompt. The Playwright-maintained permission-based clipboard test skips Firefox for its permission setup, so do not assume the minimal permission example is portable there.
WebKit and Safari
MDN likewise describes different permission behavior in Safari: it does not support those clipboard permission names and relies on activation and paste-prompt behavior for reads that would otherwise be disallowed. Playwright’s maintained test uses a different permission set for WebKit than for its other tested engines. Make the expected behavior or skip explicit in cross-browser coverage rather than applying Chromium’s setup unchanged.
Keep the test’s scope clear
This pattern tests the browser’s Async Clipboard API through navigator.clipboard. It verifies that the web app’s copy action makes text available to a browser-side read. It does not establish that a native desktop application’s clipboard bridge works identically; that requires testing the native integration in the environment and through the interface relevant to that app.
For cross-browser suites, pin Playwright and browser versions in CI, keep permission choices visible, and treat permission or activation changes as compatibility concerns. A passing browser-side clipboard assertion is useful evidence about the web flow, not a universal guarantee about operating-system clipboard behavior.
Recommended Free Tools
Quick Recap
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.

