mirror of
https://github.com/bitwarden/browser
synced 2025-01-27 11:39:42 +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,
|
tab: msg.tab,
|
||||||
details: msg.details,
|
details: msg.details,
|
||||||
});
|
});
|
||||||
this.autofillTimeout = setTimeout(async () => await this.autofillPage(), 300);
|
this.autofillTimeout = setTimeout(async () => await this.autofillPage(msg.tab), 300);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
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({
|
const totpCode = await this.autofillService.doAutoFill({
|
||||||
|
tab: tabToAutoFill,
|
||||||
cipher: this.main.loginToAutoFill,
|
cipher: this.main.loginToAutoFill,
|
||||||
pageDetails: this.pageDetailsToAutoFill,
|
pageDetails: this.pageDetailsToAutoFill,
|
||||||
fillNewPassword: true,
|
fillNewPassword: true,
|
||||||
|
@ -28,6 +28,7 @@ const BroadcasterSubscriptionId = "CurrentTabComponent";
|
|||||||
})
|
})
|
||||||
export class CurrentTabComponent implements OnInit, OnDestroy {
|
export class CurrentTabComponent implements OnInit, OnDestroy {
|
||||||
pageDetails: any[] = [];
|
pageDetails: any[] = [];
|
||||||
|
tab: chrome.tabs.Tab;
|
||||||
cardCiphers: CipherView[];
|
cardCiphers: CipherView[];
|
||||||
identityCiphers: CipherView[];
|
identityCiphers: CipherView[];
|
||||||
loginCiphers: CipherView[];
|
loginCiphers: CipherView[];
|
||||||
@ -151,6 +152,7 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
this.totpCode = await this.autofillService.doAutoFill({
|
this.totpCode = await this.autofillService.doAutoFill({
|
||||||
|
tab: this.tab,
|
||||||
cipher: cipher,
|
cipher: cipher,
|
||||||
pageDetails: this.pageDetails,
|
pageDetails: this.pageDetails,
|
||||||
doc: window.document,
|
doc: window.document,
|
||||||
@ -196,9 +198,9 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
private async load() {
|
private async load() {
|
||||||
this.loaded = false;
|
this.loaded = false;
|
||||||
const tab = await BrowserApi.getTabFromCurrentWindow();
|
this.tab = await BrowserApi.getTabFromCurrentWindow();
|
||||||
if (tab != null) {
|
if (this.tab != null) {
|
||||||
this.url = tab.url;
|
this.url = this.tab.url;
|
||||||
} else {
|
} else {
|
||||||
this.loginCiphers = [];
|
this.loginCiphers = [];
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
@ -207,9 +209,9 @@ export class CurrentTabComponent implements OnInit, OnDestroy {
|
|||||||
|
|
||||||
this.hostname = Utils.getHostname(this.url);
|
this.hostname = Utils.getHostname(this.url);
|
||||||
this.pageDetails = [];
|
this.pageDetails = [];
|
||||||
BrowserApi.tabSendMessage(tab, {
|
BrowserApi.tabSendMessage(this.tab, {
|
||||||
command: "collectPageDetails",
|
command: "collectPageDetails",
|
||||||
tab: tab,
|
tab: this.tab,
|
||||||
sender: BroadcasterSubscriptionId,
|
sender: BroadcasterSubscriptionId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -276,6 +276,7 @@ export class ViewComponent extends BaseViewComponent {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
this.totpCode = await this.autofillService.doAutoFill({
|
this.totpCode = await this.autofillService.doAutoFill({
|
||||||
|
tab: this.tab,
|
||||||
cipher: this.cipher,
|
cipher: this.cipher,
|
||||||
pageDetails: this.pageDetails,
|
pageDetails: this.pageDetails,
|
||||||
doc: window.document,
|
doc: window.document,
|
||||||
|
@ -66,7 +66,7 @@ export default class AutofillService implements AutofillServiceInterface {
|
|||||||
|
|
||||||
async doAutoFill(options: any) {
|
async doAutoFill(options: any) {
|
||||||
let totpPromise: Promise<string> = null;
|
let totpPromise: Promise<string> = null;
|
||||||
const tab = await this.getActiveTab();
|
const tab = options.tab;
|
||||||
if (!tab || !options.cipher || !options.pageDetails || !options.pageDetails.length) {
|
if (!tab || !options.cipher || !options.pageDetails || !options.pageDetails.length) {
|
||||||
throw new Error("Nothing to auto-fill.");
|
throw new Error("Nothing to auto-fill.");
|
||||||
}
|
}
|
||||||
@ -168,6 +168,7 @@ export default class AutofillService implements AutofillServiceInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const totpCode = await this.doAutoFill({
|
const totpCode = await this.doAutoFill({
|
||||||
|
tab: tab,
|
||||||
cipher: cipher,
|
cipher: cipher,
|
||||||
pageDetails: pageDetails,
|
pageDetails: pageDetails,
|
||||||
skipLastUsed: !fromCommand,
|
skipLastUsed: !fromCommand,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user