Skip to content

Commit

Permalink
Do not try to request clipboard permissions
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tobias-hotz authored and fxprunayre committed Sep 2, 2024
1 parent 849619b commit a9a9b5b
Showing 1 changed file with 23 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};
Expand Down

0 comments on commit a9a9b5b

Please sign in to comment.