1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-11 22:03:36 +00:00

safari totp copy workaround

This commit is contained in:
Kyle Spearrin
2018-04-23 11:30:12 -04:00
parent 06e56f0b57
commit b40e51a7d1

View File

@@ -45,7 +45,10 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
inSidebar = false;
showLeftHeader = false;
loaded = false;
loadedTimeout: number;
private totpCode: string;
private totpTimeout: number;
private loadedTimeout: number;
constructor(private platformUtilsService: PlatformUtilsService, private cipherService: CipherService,
private popupUtilsService: PopupUtilsService, private autofillService: AutofillService,
@@ -124,6 +127,11 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
}
async fillCipher(cipher: CipherView) {
this.totpCode = null;
if (this.totpTimeout != null) {
window.clearTimeout(this.totpTimeout);
}
if (this.pageDetails == null || this.pageDetails.length === 0) {
this.analytics.eventTrack.next({ action: 'Autofilled Error' });
this.toasterService.popAsync('error', null, this.i18nService.t('autofillError'));
@@ -131,15 +139,15 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
}
try {
const totpCode = await this.autofillService.doAutoFill({
this.totpCode = await this.autofillService.doAutoFill({
cipher: cipher,
pageDetails: this.pageDetails,
doc: window.document,
});
this.analytics.eventTrack.next({ action: 'Autofilled' });
if (totpCode != null) {
this.platformUtilsService.copyToClipboard(totpCode, { doc: window.document });
if (this.totpCode != null && !this.platformUtilsService.isSafari()) {
this.platformUtilsService.copyToClipboard(this.totpCode, { doc: window.document });
}
if (this.popupUtilsService.inPopup(window)) {
@@ -149,6 +157,15 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
this.analytics.eventTrack.next({ action: 'Autofilled Error' });
this.toasterService.popAsync('error', null, this.i18nService.t('autofillError'));
}
// Weird bug in Safari won't allow clipboard copying after promise call, so we have this workaround
if (this.platformUtilsService.isSafari()) {
this.totpTimeout = window.setTimeout(() => {
if (this.totpCode != null) {
this.platformUtilsService.copyToClipboard(this.totpCode, { doc: window.document });
}
}, 500);
}
}
searchVault() {