From a9a9b5bb2c1b0314af73c8c449078e8b46f56cab Mon Sep 17 00:00:00 2001 From: Tobias Hotz Date: Mon, 26 Aug 2024 08:34:03 +0200 Subject: [PATCH] Do not try to request clipboard permissions Clipboard permissions are only implemented in Chromium-based browsers. See https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Interact_with_the_clipboard for more details Instead, check if the browser supports the writeText/readText clipboard functions (some mobile browsers and older firefox versions do not). With these change, both Chromium-based browsers and other browsers such as firefox work correctly --- .../components/utility/UtilityDirective.js | 56 ++++++++----------- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/web-ui/src/main/resources/catalog/components/utility/UtilityDirective.js b/web-ui/src/main/resources/catalog/components/utility/UtilityDirective.js index 80834e2d4ec..425ce230238 100644 --- a/web-ui/src/main/resources/catalog/components/utility/UtilityDirective.js +++ b/web-ui/src/main/resources/catalog/components/utility/UtilityDirective.js @@ -1143,45 +1143,35 @@ return { copy: function (toCopy) { var deferred = $q.defer(); - navigator.permissions.query({ name: "clipboard-write" }).then( - function (result) { - if (result.state == "granted" || result.state == "prompt") { - navigator.clipboard.writeText(toCopy).then( - function () { - deferred.resolve(); - }, - function (r) { - console.warn(r); - deferred.reject(); - } - ); + if (navigator.clipboard?.writeText) { + navigator.clipboard.writeText(toCopy).then( + function () { + deferred.resolve(); + }, + function (r) { + console.warn(r); + deferred.reject(); } - }, - function () { - deferred.reject(); - } - ); + ); + } else { + deferred.reject(); + } return deferred.promise; }, paste: function () { var deferred = $q.defer(); - navigator.permissions.query({ name: "clipboard-read" }).then( - function (result) { - if (result.state == "granted" || result.state == "prompt") { - navigator.clipboard.readText().then( - function (text) { - deferred.resolve(text); - }, - function () { - deferred.reject(); - } - ); + if (navigator.clipboard?.readText) { + navigator.clipboard.readText().then( + function (text) { + deferred.resolve(text); + }, + function () { + deferred.reject(); } - }, - function () { - deferred.reject(); - } - ); + ); + } else { + deferred.reject(); + } return deferred.promise; } };