[Webkit-unassigned] [Bug 222262] Javascript Clipboard API write() does not work after await
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Mon May 17 04:41:57 PDT 2021
https://bugs.webkit.org/show_bug.cgi?id=222262
Thomas Steiner <tomac at google.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |tomac at google.com
--- Comment #5 from Thomas Steiner <tomac at google.com> ---
The different implementations unfortunately at the moment force developers to write code like this:
```js
copyButton.addEventListener('click', async () => {
try {
// Safari treats user activation differently:
// https://bugs.webkit.org/show_bug.cgi?id=222262.
navigator.clipboard.write([
new ClipboardItem({
'text/plain': new Promise(async (resolve) => {
const svg = svgOutput.innerHTML;
resolve(new Blob([svg], { type: 'text/plain' }));
}),
}),
]);
} catch {
// Chromium
const svg = svgOutput.innerHTML;
const blob = new Blob([svg], { type: 'text/plain' });
navigator.clipboard.write([
new ClipboardItem({
[blob.type]: blob,
}),
]);
}
});
```
Chromium is working on adding support for delayed generation of clipboard items (see https://crbug.com/1014310).
At the same time it would be great if WebKit didn't expire the user activation.
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20210517/1a7cc3e4/attachment-0001.htm>
More information about the webkit-unassigned
mailing list