Skip to content

Build your personal knowledge base with Trilium Notes

feat(client): implement clipboard fallback method

Elian Doran3ca2b24db3c9
diff --git a/apps/client/src/services/clipboard.ts b/apps/client/src/services/clipboard.ts
index 73bce475ff..40354393c9 100644
--- a/apps/client/src/services/clipboard.ts
+++ b/apps/client/src/services/clipboard.ts
@@ -120,8 +120,18 @@ export function copyText(text: string) {
if (navigator.clipboard) {
navigator.clipboard.writeText(text);
succeeded = true;
+ } else {
+ // Fallback method: https://stackoverflow.com/a/72239825
+ const textArea = document.createElement("textarea");
+ textArea.value = text;
+ document.body.appendChild(textArea);
+ textArea.focus();
+ textArea.select();
+ succeeded = document.execCommand('copy');
+ document.body.removeChild(textArea);
}
} catch (e) {
+ console.warn(e);
succeeded = false;
}