diff --git a/jslib b/jslib index 79c15a1841..21d011554c 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 79c15a18414190ffce39a126ccc9078405287693 +Subproject commit 21d011554c1c7d5e497241965bc775cfc1001d16 diff --git a/src/manifest.json b/src/manifest.json index d25dedd744..60704c15a1 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -71,6 +71,7 @@ "contextMenus", "storage", "unlimitedStorage", + "clipboardRead", "clipboardWrite", "idle", "http://*/*", diff --git a/src/services/browserPlatformUtils.service.ts b/src/services/browserPlatformUtils.service.ts index 6d8fb22233..b272a05758 100644 --- a/src/services/browserPlatformUtils.service.ts +++ b/src/services/browserPlatformUtils.service.ts @@ -210,6 +210,39 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService } } + async readFromClipboard(options?: any): Promise { + 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) { if (this.showDialogResolves.has(dialogId)) { const resolveObj = this.showDialogResolves.get(dialogId);