diff --git a/web/src/routes/servers/[alias]/users/+page.svelte b/web/src/routes/servers/[alias]/users/+page.svelte index 95ec4b6..ae0cbde 100644 --- a/web/src/routes/servers/[alias]/users/+page.svelte +++ b/web/src/routes/servers/[alias]/users/+page.svelte @@ -163,7 +163,31 @@ } function copy(text: string) { - void navigator.clipboard.writeText(text); + const value = String(text ?? ''); + if (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) { + void navigator.clipboard.writeText(value).catch(() => fallbackCopy(value)); + } else { + fallbackCopy(value); + } + } + + function fallbackCopy(value: string) { + if (typeof document === 'undefined') return; + const ta = document.createElement('textarea'); + ta.value = value; + ta.setAttribute('readonly', ''); + ta.style.position = 'fixed'; + ta.style.left = '-9999px'; + ta.style.top = '0'; + document.body.appendChild(ta); + ta.select(); + try { + document.execCommand('copy'); + } catch { + // ignore + } finally { + ta.remove(); + } } diff --git a/web/src/routes/users/+page.svelte b/web/src/routes/users/+page.svelte index 1700719..ce3e1b1 100644 --- a/web/src/routes/users/+page.svelte +++ b/web/src/routes/users/+page.svelte @@ -34,7 +34,12 @@ onMount(load); function copy(text: string) { - void navigator.clipboard.writeText(text); + const value = String(text ?? ''); + if (typeof navigator !== 'undefined' && navigator.clipboard?.writeText) { + void navigator.clipboard.writeText(value).catch(() => fallbackCopy(value)); + } else { + fallbackCopy(value); + } } function openUser(username: string | null | undefined) { @@ -42,6 +47,25 @@ if (!u) return; void goto(`/users/${encodeURIComponent(u)}`); } + + function fallbackCopy(value: string) { + if (typeof document === 'undefined') return; + const ta = document.createElement('textarea'); + ta.value = value; + ta.setAttribute('readonly', ''); + ta.style.position = 'fixed'; + ta.style.left = '-9999px'; + ta.style.top = '0'; + document.body.appendChild(ta); + ta.select(); + try { + document.execCommand('copy'); + } catch { + // ignore + } finally { + ta.remove(); + } + }