diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2022-03-13 21:17:48 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-13 21:17:48 -0400 |
commit | 59ae55252e69f844ab914c1eb516ac851f08ac89 (patch) | |
tree | e56318878f35aeb8b4335159e058fdf8a698dd3c | |
parent | f98f5f939552d14b014396ce933bba4faa9607bb (diff) |
Update ClipboardReader.getImage implementation (#2085)
-rw-r--r-- | ext/js/comm/clipboard-reader.js | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/ext/js/comm/clipboard-reader.js b/ext/js/comm/clipboard-reader.js index c7283e55..7a4744ca 100644 --- a/ext/js/comm/clipboard-reader.js +++ b/ext/js/comm/clipboard-reader.js @@ -113,17 +113,24 @@ class ClipboardReader { typeof navigator.clipboard !== 'undefined' && typeof navigator.clipboard.read === 'function' ) { - // This function is behind the Firefox flag: dom.events.asyncClipboard.dataTransfer - let files; + // This function is behind the Firefox flag: dom.events.asyncClipboard.read + // See: https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/read#browser_compatibility + let items; try { - ({files} = await navigator.clipboard.read()); + items = await navigator.clipboard.read(); } catch (e) { return null; } - for (const file of files) { - if (MediaUtil.getFileExtensionFromImageMediaType(file.type) !== null) { - return await this._readFileAsDataURL(file); + for (const item of items) { + for (const type of item.types) { + if (!MediaUtil.getFileExtensionFromImageMediaType(type)) { continue; } + try { + const blob = await item.getType(type); + return await this._readFileAsDataURL(blob); + } catch (e) { + // NOP + } } } return null; |