Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions website/src/components/LLMButtons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,23 @@ const onCopyAsMarkdownClick = async ({ setCopyingStatus, currentUrl }) => {
try {
setCopyingStatus('loading');

const response = await fetch(markdownUrl);
// Safari requires clipboard writes to be created synchronously inside the user gesture.
// We therefore pass a Promise that resolves to a Blob into ClipboardItem instead of
// awaiting fetch first — otherwise Safari would reject the clipboard operation.
const markdownContent = new ClipboardItem({
'text/plain': fetch(markdownUrl)
.then((response) => {
if (!response.ok) {
throw new Error(`Failed to fetch markdown: ${response.status}`);
}
return response.text();
})
.then((content) => new Blob([content], { type: 'text/plain' })),
});

if (!response.ok) {
throw new Error(`Failed to fetch markdown: ${response.status}`);
}
await navigator.clipboard.write([markdownContent]);

const markdownContent = await response.text();
await navigator.clipboard.writeText(markdownContent);
// Show success feedback
setCopyingStatus('copied');
} catch (error) {
console.error('Failed to copy markdown content:', error);
Expand Down
Loading