Open gustav-larsson opened 1 year ago
I have run into the same issue and I can add a small repo later.
+1
mark, I write a simple util function:
export const writeTextToClipboard = async (page, text) => {
await page.evaluate((text) => {
if (navigator.clipboard) {
// Write the URL to the clipboard
navigator.clipboard.writeText(text)
.then((resp) => {
console.log('eval done', resp)
})
.catch(err => {
console.error('Error copying to clipboard:', err);
});
} else {
// Fallback for browsers that do not support the Clipboard API
console.warn('Clipboard API not supported in this browser');
}
}, [text])
}
It works in headed browser but not work in headless browser (uncheck 'Show browser' option in VSCode plugun)
It seems that cutting in headless mode only allows to do navigator.clipboard.readText()
and not .read()
. Our workaround is to check if there is type on the clipboard item, if not, resort to readText()
System info
or
Config file
Steps
Expected
[I expect to have the ClipboardItem in my clipboard instead of the raw text]
Actual
[I get the raw text]
This works in headed Playwright Chromium and headless puppeteer Chromium 107