mirror of
https://github.com/bitwarden/browser
synced 2025-12-13 23:03:32 +00:00
use navigator.clipboard to copy text if available
This commit is contained in:
@@ -206,10 +206,19 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
|
||||
}
|
||||
|
||||
copyToClipboard(text: string, options?: any): void {
|
||||
const doc = options ? options.doc : window.document;
|
||||
if ((window as any).clipboardData && (window as any).clipboardData.setData) {
|
||||
let win = window;
|
||||
let doc = window.document;
|
||||
if (options && options.window) {
|
||||
win = options.window;
|
||||
doc = win.document;
|
||||
} else if (options && options.doc) {
|
||||
doc = options.doc;
|
||||
}
|
||||
if ((win as any).navigator.clipboard && (win as any).navigator.clipboard.writeText) {
|
||||
(win as any).navigator.clipboard.writeText(text);
|
||||
} else if ((win as any).clipboardData && (win as any).clipboardData.setData) {
|
||||
// IE specific code path to prevent textarea being shown while dialog is visible.
|
||||
(window as any).clipboardData.setData('Text', text);
|
||||
(win as any).clipboardData.setData('Text', text);
|
||||
} else if (doc.queryCommandSupported && doc.queryCommandSupported('copy')) {
|
||||
const textarea = doc.createElement('textarea');
|
||||
textarea.textContent = text;
|
||||
|
||||
Reference in New Issue
Block a user