diff --git a/apps/browser/src/background/runtime.background.ts b/apps/browser/src/background/runtime.background.ts index 24513ed5bb..e7e06e5c41 100644 --- a/apps/browser/src/background/runtime.background.ts +++ b/apps/browser/src/background/runtime.background.ts @@ -143,7 +143,7 @@ export default class RuntimeBackground { tab: msg.tab, details: msg.details, }); - this.autofillTimeout = setTimeout(async () => await this.autofillPage(), 300); + this.autofillTimeout = setTimeout(async () => await this.autofillPage(msg.tab), 300); break; default: break; @@ -205,8 +205,9 @@ export default class RuntimeBackground { } } - private async autofillPage() { + private async autofillPage(tabToAutoFill: chrome.tabs.Tab) { const totpCode = await this.autofillService.doAutoFill({ + tab: tabToAutoFill, cipher: this.main.loginToAutoFill, pageDetails: this.pageDetailsToAutoFill, fillNewPassword: true, diff --git a/apps/browser/src/popup/vault/current-tab.component.ts b/apps/browser/src/popup/vault/current-tab.component.ts index 97c0af2234..b196f9180d 100644 --- a/apps/browser/src/popup/vault/current-tab.component.ts +++ b/apps/browser/src/popup/vault/current-tab.component.ts @@ -28,6 +28,7 @@ const BroadcasterSubscriptionId = "CurrentTabComponent"; }) export class CurrentTabComponent implements OnInit, OnDestroy { pageDetails: any[] = []; + tab: chrome.tabs.Tab; cardCiphers: CipherView[]; identityCiphers: CipherView[]; loginCiphers: CipherView[]; @@ -151,6 +152,7 @@ export class CurrentTabComponent implements OnInit, OnDestroy { try { this.totpCode = await this.autofillService.doAutoFill({ + tab: this.tab, cipher: cipher, pageDetails: this.pageDetails, doc: window.document, @@ -196,9 +198,9 @@ export class CurrentTabComponent implements OnInit, OnDestroy { private async load() { this.loaded = false; - const tab = await BrowserApi.getTabFromCurrentWindow(); - if (tab != null) { - this.url = tab.url; + this.tab = await BrowserApi.getTabFromCurrentWindow(); + if (this.tab != null) { + this.url = this.tab.url; } else { this.loginCiphers = []; this.loaded = true; @@ -207,9 +209,9 @@ export class CurrentTabComponent implements OnInit, OnDestroy { this.hostname = Utils.getHostname(this.url); this.pageDetails = []; - BrowserApi.tabSendMessage(tab, { + BrowserApi.tabSendMessage(this.tab, { command: "collectPageDetails", - tab: tab, + tab: this.tab, sender: BroadcasterSubscriptionId, }); diff --git a/apps/browser/src/popup/vault/view.component.ts b/apps/browser/src/popup/vault/view.component.ts index 87f94ab75b..0655212e6f 100644 --- a/apps/browser/src/popup/vault/view.component.ts +++ b/apps/browser/src/popup/vault/view.component.ts @@ -276,6 +276,7 @@ export class ViewComponent extends BaseViewComponent { try { this.totpCode = await this.autofillService.doAutoFill({ + tab: this.tab, cipher: this.cipher, pageDetails: this.pageDetails, doc: window.document, diff --git a/apps/browser/src/services/autofill.service.ts b/apps/browser/src/services/autofill.service.ts index 837a013f45..341eb723d1 100644 --- a/apps/browser/src/services/autofill.service.ts +++ b/apps/browser/src/services/autofill.service.ts @@ -66,7 +66,7 @@ export default class AutofillService implements AutofillServiceInterface { async doAutoFill(options: any) { let totpPromise: Promise = null; - const tab = await this.getActiveTab(); + const tab = options.tab; if (!tab || !options.cipher || !options.pageDetails || !options.pageDetails.length) { throw new Error("Nothing to auto-fill."); } @@ -168,6 +168,7 @@ export default class AutofillService implements AutofillServiceInterface { } const totpCode = await this.doAutoFill({ + tab: tab, cipher: cipher, pageDetails: pageDetails, skipLastUsed: !fromCommand,