From f8f0eeb2995bbc072b876519fd18bf33ab974ea8 Mon Sep 17 00:00:00 2001 From: Ardis Lu Date: Sat, 27 Jul 2024 22:21:25 -0700 Subject: [PATCH] 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. --- index.html | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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'); }); -- 2.47.3