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:
@@ -45,7 +45,10 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
|
|||||||
inSidebar = false;
|
inSidebar = false;
|
||||||
showLeftHeader = false;
|
showLeftHeader = false;
|
||||||
loaded = false;
|
loaded = false;
|
||||||
loadedTimeout: number;
|
|
||||||
|
private totpCode: string;
|
||||||
|
private totpTimeout: number;
|
||||||
|
private loadedTimeout: number;
|
||||||
|
|
||||||
constructor(private platformUtilsService: PlatformUtilsService, private cipherService: CipherService,
|
constructor(private platformUtilsService: PlatformUtilsService, private cipherService: CipherService,
|
||||||
private popupUtilsService: PopupUtilsService, private autofillService: AutofillService,
|
private popupUtilsService: PopupUtilsService, private autofillService: AutofillService,
|
||||||
@@ -124,6 +127,11 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fillCipher(cipher: CipherView) {
|
async fillCipher(cipher: CipherView) {
|
||||||
|
this.totpCode = null;
|
||||||
|
if (this.totpTimeout != null) {
|
||||||
|
window.clearTimeout(this.totpTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
if (this.pageDetails == null || this.pageDetails.length === 0) {
|
if (this.pageDetails == null || this.pageDetails.length === 0) {
|
||||||
this.analytics.eventTrack.next({ action: 'Autofilled Error' });
|
this.analytics.eventTrack.next({ action: 'Autofilled Error' });
|
||||||
this.toasterService.popAsync('error', null, this.i18nService.t('autofillError'));
|
this.toasterService.popAsync('error', null, this.i18nService.t('autofillError'));
|
||||||
@@ -131,15 +139,15 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const totpCode = await this.autofillService.doAutoFill({
|
this.totpCode = await this.autofillService.doAutoFill({
|
||||||
cipher: cipher,
|
cipher: cipher,
|
||||||
pageDetails: this.pageDetails,
|
pageDetails: this.pageDetails,
|
||||||
doc: window.document,
|
doc: window.document,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.analytics.eventTrack.next({ action: 'Autofilled' });
|
this.analytics.eventTrack.next({ action: 'Autofilled' });
|
||||||
if (totpCode != null) {
|
if (this.totpCode != null && !this.platformUtilsService.isSafari()) {
|
||||||
this.platformUtilsService.copyToClipboard(totpCode, { doc: window.document });
|
this.platformUtilsService.copyToClipboard(this.totpCode, { doc: window.document });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.popupUtilsService.inPopup(window)) {
|
if (this.popupUtilsService.inPopup(window)) {
|
||||||
@@ -149,6 +157,15 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
|
|||||||
this.analytics.eventTrack.next({ action: 'Autofilled Error' });
|
this.analytics.eventTrack.next({ action: 'Autofilled Error' });
|
||||||
this.toasterService.popAsync('error', null, this.i18nService.t('autofillError'));
|
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() {
|
searchVault() {
|
||||||
|
|||||||
Reference in New Issue
Block a user