fix: handle clipboard copy failures gracefully #35
Conversation
twoGiants
left a comment
There was a problem hiding this comment.
Keep it up and see my comment below 😸 👍
|
Doesn't he error happen before the promises comes to existence? I think the catch should be one level up or we should simply check if It crashes with access Regardless it's definitely important to have that catch block! One never know what throws. |
diff --git a/pages/index.html b/pages/index.html
index 7023eff..78753e7 100644
--- a/pages/index.html
+++ b/pages/index.html
@@ -240,6 +240,11 @@
if (strip) {
text = text.split('\n').map(l => l.startsWith(strip) ? l.slice(strip.length) : l).join('\n');
}
+ if (typeof navigator.clipboard === 'undefined') {
+ btn.classList.add('copy-error');
+ setTimeout(() => { btn.classList.remove('copy-error'); }, 1500);
+ return
+ }
navigator.clipboard.writeText(text).then(() => {
btn.classList.add('copied');
setTimeout(() => { btn.classList.remove('copied'); }, 1500); |
|
Hmm it appears the above is issue only if testing site under plain HTTP. In real usage with HTTPS it probably won't happen. |
|
Can you add a screenshot? Then I don't need to manual test locally. One nit. Also squash commits and use claude for a nice commit message. We have a guide |
The copy buttons on the landing page silently failed when the Clipboard API was unavailable (non-HTTPS) or when writeText was rejected. Added a pre-check for navigator.clipboard and a .catch() handler, both showing an error state with an X icon and "Copy failed" label. Co-Authored-By: Claude <noreply@anthropic.com>


Changes
Per issue description:
@matejvasek is it that simple? :)