From e9be7e712d0e2ea9eadb961b615395ba0c58a199 Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 9 Apr 2022 19:38:05 +0200 Subject: [PATCH] futureproof clipboard function --- copyparty/web/browser.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 63231236..0aafc99e 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -747,13 +747,25 @@ var widget = (function () { o.style.cssText = 'position:fixed;top:45%;left:48%;padding:1em;z-index:9'; o.value = m; document.body.appendChild(o); - o.focus(); - o.select(); - document.execCommand("copy"); - o.value = 'copied to clipboard '; - setTimeout(function () { - document.body.removeChild(o); - }, 500); + + var cln = function () { + o.value = 'copied to clipboard '; + setTimeout(function () { + document.body.removeChild(o); + }, 500); + }; + var fb = function () { + console.log('fb'); + o.focus(); + o.select(); + document.execCommand("copy"); + cln(); + }; + try { + // https only + navigator.clipboard.writeText(m).then(cln, fb); + } + catch (ex) { fb(); } }; r.set(sread('au_open') == 1); setTimeout(function () {