In headless mode, the following code snippet hangs
await page.evaluate(() => navigator.clipboard.readText())
In headful mode, the same snippet causes an error
DOMException: Read permission denied.
Even if window.isSecureContext()
is true.
So in either case, we use the permissions api grant permissions to read the clipboard
const context = browser.defaultBrowserContext();
context.overridePermissions(url, ['clipboard-read', 'clipboard-write']);
This failed with a write permission denied, so I tried clipboard-sanitized-write
, which worked! This appears to have been added to the permissions supported by puppeteer only recently .