From 86a9b24b5fda03979b7976adc2fcbb9f1c0f90b5 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 11 Dec 2023 14:18:45 -0300 Subject: warn when clipboard is not available --- packages/web-util/src/components/CopyButton.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'packages/web-util/src') diff --git a/packages/web-util/src/components/CopyButton.tsx b/packages/web-util/src/components/CopyButton.tsx index 0096da365..e76447291 100644 --- a/packages/web-util/src/components/CopyButton.tsx +++ b/packages/web-util/src/components/CopyButton.tsx @@ -20,8 +20,13 @@ export function CopiedIcon(): VNode { export function CopyButton({ class: clazz, getContent }: { class: string, getContent: () => string }): VNode { const [copied, setCopied] = useState(false); function copyText(): void { - navigator.clipboard.writeText(getContent() || ""); - setCopied(true); + if (!navigator.clipboard && !window.isSecureContext) { + alert('clipboard is not available on insecure context (http)') + } + if (navigator.clipboard) { + navigator.clipboard.writeText(getContent() || ""); + setCopied(true); + } } useEffect(() => { if (copied) { -- cgit v1.2.3