mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-23 21:31:29 +01:00
implement readFromClipboard
This commit is contained in:
parent
9792a7ade5
commit
91a0566f2c
2
jslib
2
jslib
@ -1 +1 @@
|
|||||||
Subproject commit 79c15a18414190ffce39a126ccc9078405287693
|
Subproject commit 21d011554c1c7d5e497241965bc775cfc1001d16
|
@ -71,6 +71,7 @@
|
|||||||
"contextMenus",
|
"contextMenus",
|
||||||
"storage",
|
"storage",
|
||||||
"unlimitedStorage",
|
"unlimitedStorage",
|
||||||
|
"clipboardRead",
|
||||||
"clipboardWrite",
|
"clipboardWrite",
|
||||||
"idle",
|
"idle",
|
||||||
"http://*/*",
|
"http://*/*",
|
||||||
|
@ -210,6 +210,39 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async readFromClipboard(options?: any): Promise<string> {
|
||||||
|
let win = window;
|
||||||
|
let doc = window.document;
|
||||||
|
if (options && (options.window || options.win)) {
|
||||||
|
win = options.window || options.win;
|
||||||
|
doc = win.document;
|
||||||
|
} else if (options && options.doc) {
|
||||||
|
doc = options.doc;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isFirefox() && (win as any).navigator.clipboard && (win as any).navigator.clipboard.readText) {
|
||||||
|
return await (win as any).navigator.clipboard.readText();
|
||||||
|
} else if (doc.queryCommandSupported && doc.queryCommandSupported('paste')) {
|
||||||
|
const textarea = doc.createElement('textarea');
|
||||||
|
// Prevent scrolling to bottom of page in MS Edge.
|
||||||
|
textarea.style.position = 'fixed';
|
||||||
|
doc.body.appendChild(textarea);
|
||||||
|
textarea.focus();
|
||||||
|
try {
|
||||||
|
// Security exception may be thrown by some browsers.
|
||||||
|
if (doc.execCommand('paste')) {
|
||||||
|
return textarea.value;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// tslint:disable-next-line
|
||||||
|
console.warn('Read from clipboard failed.', e);
|
||||||
|
} finally {
|
||||||
|
doc.body.removeChild(textarea);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
resolveDialogPromise(dialogId: number, confirmed: boolean) {
|
resolveDialogPromise(dialogId: number, confirmed: boolean) {
|
||||||
if (this.showDialogResolves.has(dialogId)) {
|
if (this.showDialogResolves.has(dialogId)) {
|
||||||
const resolveObj = this.showDialogResolves.get(dialogId);
|
const resolveObj = this.showDialogResolves.get(dialogId);
|
||||||
|
Loading…
Reference in New Issue
Block a user