feat(observability): guard navigator.clipboard and handle rejection in copyId

Adds availability guard (navigator.clipboard may be undefined in non-HTTPS
contexts) and a rejection handler so clipboard-denied errors are silently
caught rather than becoming unhandled promise rejections. Tests cover the
success feedback and the silent-failure path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-05-17 10:24:35 +02:00
parent 2023ea2931
commit c779ec59f9
2 changed files with 44 additions and 4 deletions

View File

@@ -7,10 +7,16 @@ let copied = $state(false);
function copyId() {
const id = page.error?.errorId;
if (!id) return;
navigator.clipboard.writeText(id).then(() => {
copied = true;
setTimeout(() => (copied = false), 2000);
});
if (!navigator.clipboard) return;
navigator.clipboard.writeText(id).then(
() => {
copied = true;
setTimeout(() => (copied = false), 2000);
},
() => {
/* clipboard denied or unavailable — select-all on the <code> element remains */
}
);
}
</script>