mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-22 11:45:59 +01:00
[PS-94] Ensure autofill always uses the same tab (#3066)
* Require specifying a tab in doAutoFill options to ensure only the desired tab is filled * Specify well defined type for added tab properties * Replace new tabToAutoFill property with parameter
This commit is contained in:
parent
eaec97506e
commit
9eefb4ad16
@ -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,
|
||||
|
@ -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,
|
||||
});
|
||||
|
||||
|
@ -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,
|
||||
|
@ -66,7 +66,7 @@ export default class AutofillService implements AutofillServiceInterface {
|
||||
|
||||
async doAutoFill(options: any) {
|
||||
let totpPromise: Promise<string> = 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,
|
||||
|
Loading…
Reference in New Issue
Block a user