Wanted to share a frustrating interop issue with copy & paste in the Async Clipboard API between Safari and Chrome. This is actual code:
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,
}),
]);
}
});