Update ClipboardReader.getImage implementation (#2085)
This commit is contained in:
parent
f98f5f9395
commit
59ae55252e
@ -113,17 +113,24 @@ class ClipboardReader {
|
|||||||
typeof navigator.clipboard !== 'undefined' &&
|
typeof navigator.clipboard !== 'undefined' &&
|
||||||
typeof navigator.clipboard.read === 'function'
|
typeof navigator.clipboard.read === 'function'
|
||||||
) {
|
) {
|
||||||
// This function is behind the Firefox flag: dom.events.asyncClipboard.dataTransfer
|
// This function is behind the Firefox flag: dom.events.asyncClipboard.read
|
||||||
let files;
|
// See: https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/read#browser_compatibility
|
||||||
|
let items;
|
||||||
try {
|
try {
|
||||||
({files} = await navigator.clipboard.read());
|
items = await navigator.clipboard.read();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const file of files) {
|
for (const item of items) {
|
||||||
if (MediaUtil.getFileExtensionFromImageMediaType(file.type) !== null) {
|
for (const type of item.types) {
|
||||||
return await this._readFileAsDataURL(file);
|
if (!MediaUtil.getFileExtensionFromImageMediaType(type)) { continue; }
|
||||||
|
try {
|
||||||
|
const blob = await item.getType(type);
|
||||||
|
return await this._readFileAsDataURL(blob);
|
||||||
|
} catch (e) {
|
||||||
|
// NOP
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user