use `navigator.clipboard` to copy text if available
This commit is contained in:
parent
2a9cd36a01
commit
ada83aae8f
|
@ -65,7 +65,7 @@ export default class CommandsBackground {
|
|||
|
||||
const options = await this.passwordGenerationService.getOptions();
|
||||
const password = await this.passwordGenerationService.generatePassword(options);
|
||||
this.platformUtilsService.copyToClipboard(password);
|
||||
this.platformUtilsService.copyToClipboard(password, { window: window });
|
||||
this.passwordGenerationService.addHistory(password);
|
||||
|
||||
this.analytics.ga('send', {
|
||||
|
|
|
@ -37,7 +37,7 @@ export default class ContextMenusBackground {
|
|||
private async generatePasswordToClipboard() {
|
||||
const options = await this.passwordGenerationService.getOptions();
|
||||
const password = await this.passwordGenerationService.generatePassword(options);
|
||||
this.platformUtilsService.copyToClipboard(password);
|
||||
this.platformUtilsService.copyToClipboard(password, { window: window });
|
||||
this.passwordGenerationService.addHistory(password);
|
||||
|
||||
this.analytics.ga('send', {
|
||||
|
@ -73,13 +73,13 @@ export default class ContextMenusBackground {
|
|||
hitType: 'event',
|
||||
eventAction: 'Copied Username From Context Menu',
|
||||
});
|
||||
this.platformUtilsService.copyToClipboard(cipher.login.username);
|
||||
this.platformUtilsService.copyToClipboard(cipher.login.username, { window: window });
|
||||
} else if (info.parentMenuItemId === 'copy-password') {
|
||||
this.analytics.ga('send', {
|
||||
hitType: 'event',
|
||||
eventAction: 'Copied Password From Context Menu',
|
||||
});
|
||||
this.platformUtilsService.copyToClipboard(cipher.login.password);
|
||||
this.platformUtilsService.copyToClipboard(cipher.login.password, { window: window });
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
|
@ -149,9 +149,8 @@ export default class RuntimeBackground {
|
|||
tab: msg.tab,
|
||||
details: msg.details,
|
||||
}], msg.sender === 'autofill_cmd');
|
||||
|
||||
if (totpCode !== null && !this.platformUtilsService.isFirefox()) {
|
||||
this.platformUtilsService.copyToClipboard(totpCode);
|
||||
if (totpCode !== null) {
|
||||
this.platformUtilsService.copyToClipboard(totpCode, { window: window });
|
||||
}
|
||||
break;
|
||||
case 'contextMenu':
|
||||
|
@ -178,8 +177,8 @@ export default class RuntimeBackground {
|
|||
pageDetails: this.pageDetailsToAutoFill,
|
||||
});
|
||||
|
||||
if (totpCode !== null && !this.platformUtilsService.isFirefox()) {
|
||||
this.platformUtilsService.copyToClipboard(totpCode);
|
||||
if (totpCode !== null) {
|
||||
this.platformUtilsService.copyToClipboard(totpCode, { window: window });
|
||||
}
|
||||
|
||||
// reset
|
||||
|
|
|
@ -52,7 +52,7 @@ export class ActionButtonsComponent {
|
|||
}
|
||||
|
||||
this.analytics.eventTrack.next({ action: 'Copied ' + aType });
|
||||
this.platformUtilsService.copyToClipboard(value, { doc: window.document });
|
||||
this.platformUtilsService.copyToClipboard(value, { window: window });
|
||||
this.toasterService.popAsync('info', null,
|
||||
this.i18nService.t('valueCopied', this.i18nService.t(typeI18nKey)));
|
||||
}
|
||||
|
|
|
@ -146,7 +146,7 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
|
|||
this.totpCode = totpCode;
|
||||
this.analytics.eventTrack.next({ action: 'Autofilled' });
|
||||
if (totpCode != null && !this.platformUtilsService.isSafari()) {
|
||||
this.platformUtilsService.copyToClipboard(totpCode, { doc: window.document });
|
||||
this.platformUtilsService.copyToClipboard(totpCode, { window: window });
|
||||
}
|
||||
|
||||
if (this.popupUtilsService.inPopup(window)) {
|
||||
|
@ -164,7 +164,7 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
|
|||
if (cipher.type === CipherType.Login && this.platformUtilsService.isSafari()) {
|
||||
this.totpTimeout = window.setTimeout(() => {
|
||||
if (this.totpCode != null) {
|
||||
this.platformUtilsService.copyToClipboard(this.totpCode, { doc: window.document });
|
||||
this.platformUtilsService.copyToClipboard(this.totpCode, { window: window });
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue