diff --git a/src/components/PageHeading.tsx b/src/components/PageHeading.tsx index f488f4a9..ba4b413a 100644 --- a/src/components/PageHeading.tsx +++ b/src/components/PageHeading.tsx @@ -41,13 +41,20 @@ function CopyAsMarkdownButton() { return () => clearTimeout(timer); }, [copied]); - async function handleCopy() { + async function fetchPageBlob() { const cleanPath = asPath.split(/[?#]/)[0]; + const res = await fetch(cleanPath + '.md'); + if (!res.ok) throw new Error('Failed to fetch'); + const text = await res.text(); + return new Blob([text], {type: 'text/plain'}); + } + + async function handleCopy() { try { - const res = await fetch(cleanPath + '.md'); - if (!res.ok) return; - const text = await res.text(); - await navigator.clipboard.writeText(text); + await navigator.clipboard.write([ + // Don't wait for the blob, or Safari will refuse clipboard access + new ClipboardItem({'text/plain': fetchPageBlob()}), + ]); setCopied(true); } catch { // Silently fail