From: Ardis Lu Date: Sun, 28 Jul 2024 05:21:25 +0000 (-0700) Subject: Fix "Copy permalink" button on Safari X-Git-Url: https://git.ardis.lu/?a=commitdiff_plain;h=f8f0eeb2995bbc072b876519fd18bf33ab974ea8;p=event-hashes Fix "Copy permalink" button on Safari This is a workaround for: https://bugs.webkit.org/show_bug.cgi?id=222262 Safari considers the user activation to be expired after an `await`, so `writeText` no longer has permission. Workaround is to avoid `await` and pass a promise instead. --- diff --git a/index.html b/index.html index 9b54f3d..cc7429f 100644 --- a/index.html +++ b/index.html @@ -426,10 +426,13 @@ }, 2000); } - document.querySelector('#copy-permalink').addEventListener('click', async e => { - const b64 = await textToGzipBase64(textarea.value); - const url = `${location.origin}#${b64}`; - navigator.clipboard.writeText(url); + document.querySelector('#copy-permalink').addEventListener('click', e => { + const data = [new ClipboardItem({ + 'text/plain': textToGzipBase64(textarea.value) + .then(b64 => `${location.origin}#${b64}`) + .then(url => new Blob([url], { type: 'text/plain' })) + })]; + navigator.clipboard.write(data); debounceButton(e.target, icons['permalink'], 'Copy permalink to clipboard'); });