From 058766f617e39f57bd56d68557b32797d70d4947 Mon Sep 17 00:00:00 2001 From: Andreas <962868+Anteus@users.noreply.github.com> Date: Mon, 17 Oct 2022 09:45:21 +0200 Subject: [PATCH] fix: copy to clipboard on non secure context (no SSL) #521 --- .../Torrent/TorrentRightClickMenu.vue | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/components/Torrent/TorrentRightClickMenu.vue b/src/components/Torrent/TorrentRightClickMenu.vue index a2edd959..af704b34 100644 --- a/src/components/Torrent/TorrentRightClickMenu.vue +++ b/src/components/Torrent/TorrentRightClickMenu.vue @@ -397,7 +397,22 @@ export default { qbit.setAutoTMM(this.hashes, !this.torrent.auto_tmm) }, copyToClipBoard(text) { - navigator.clipboard.writeText(text) + if (navigator.clipboard && window.isSecureContext) { + navigator.clipboard.writeText(text) + } else { + const textArea = document.createElement('textarea') + textArea.value = text + textArea.style.position = 'fixed' + textArea.style.opacity = '0' + document.body.appendChild(textArea) + textArea.select() + try { + document.execCommand('copy') + } catch (err) { + console.error('Unable to copy to clipboard', err) + } + document.body.removeChild(textArea) + } } } } @@ -408,4 +423,4 @@ export default { font-size: 1em; } } - \ No newline at end of file +