Reputation: 21
The following code throws an exception: Uncaught Error Error: Evaluation failed: DOMException: Write permission denied.
Environment: Nodejs version: v16.13.1 puppeteer version: [email protected]
'use strict'; const puppeteer = require('puppeteer'); const URL = 'https://google.com'; (async () => { const browser = await puppeteer.launch(); const context = browser.defaultBrowserContext(); context.overridePermissions(URL, ['clipboard-read', 'clipboard-write']); const page = await browser.newPage(); await page.goto(URL, { waitUntil: 'networkidle2', }); await page.evaluate(() => navigator.clipboard.writeText("Injected")); const value = await page.evaluate(() => navigator.clipboard.readText()); console.log(value); })();
Upvotes: 2
Views: 1068
Reputation: 46
I have the same problem. The response of "It just works in headful mode" is wrong.
You need to override browser permissions.
const context = await browser.defaultBrowserContext();
await context.overridePermissions(spec.url, ['clipboard-read', 'clipboard-write']);
Upvotes: 0