summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-01-30 15:03:19 -0500
committerGitHub <noreply@github.com>2021-01-30 15:03:19 -0500
commita802666d8dde251d996fee66b4d96f69c044edf4 (patch)
tree72f80ab25fe62b1aa34523c37f03351cd54f0236
parent7177694419f79986140a81cc5d7d259741e2b848 (diff)
Update error handling for navigator.clipboard (#1333)
-rw-r--r--ext/bg/js/clipboard-reader.js17
1 files changed, 14 insertions, 3 deletions
diff --git a/ext/bg/js/clipboard-reader.js b/ext/bg/js/clipboard-reader.js
index ae432246..275c2d60 100644
--- a/ext/bg/js/clipboard-reader.js
+++ b/ext/bg/js/clipboard-reader.js
@@ -58,7 +58,7 @@ class ClipboardReader {
/*
Notes:
document.execCommand('paste') doesn't work on Firefox.
- This may be a bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1603985
+ See: https://bugzilla.mozilla.org/show_bug.cgi?id=1603985
Therefore, navigator.clipboard.readText() is used on Firefox.
navigator.clipboard.readText() can't be used in Chrome for two reasons:
@@ -68,7 +68,12 @@ class ClipboardReader {
non-extension permission for clipboard access.
*/
if (this._isFirefox()) {
- return await navigator.clipboard.readText();
+ try {
+ return await navigator.clipboard.readText();
+ } catch (e) {
+ // Error is undefined, due to permissions
+ throw new Error('Cannot read clipboard text; check extension permissions');
+ }
}
const document = this._document;
@@ -107,7 +112,13 @@ class ClipboardReader {
typeof navigator.clipboard.read === 'function'
) {
// This function is behind the Firefox flag: dom.events.asyncClipboard.dataTransfer
- const {files} = await navigator.clipboard.read();
+ let files;
+ try {
+ ({files} = await navigator.clipboard.read());
+ } catch (e) {
+ return null;
+ }
+
for (const file of files) {
if (this._mediaUtility.getFileExtensionFromImageMediaType(file.type) !== null) {
return await this._readFileAsDataURL(file);