Text to copy to clipboard.
Promise that resolves when copy succeeds.
export async function copyToClipboard(text: string): Promise<void> {
// Try the standard Clipboard API first
if (navigator.clipboard && globalThis.isSecureContext) {
try {
await navigator.clipboard.writeText(text);
return;
} catch (err) {
// Document may not be focused in Electron - continue to fallback
if (err instanceof Error && err.message.includes("not focused")) {
// Expected in some Electron contexts, use fallback
} else {
throw err;
}
}
}
// Fallback: Use textarea selection method (works in Electron)
fallbackCopyToClipboard(text);
}
Copies text to clipboard with Electron-compatible fallback for unfocused documents.