1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-13 14:53:33 +00:00

[PM-15943] - fix extension flicker when filling in a password (#13143)

* update lastUsedDate in background script

* fix tests
This commit is contained in:
Jordan Aasen
2025-02-04 12:38:14 -08:00
committed by GitHub
parent 0b17d9e74d
commit 1b3bc71e50
4 changed files with 19 additions and 5 deletions

View File

@@ -747,7 +747,7 @@ describe("AutofillService", () => {
jest.spyOn(autofillService as any, "generateFillScript");
jest.spyOn(autofillService as any, "generateLoginFillScript");
jest.spyOn(logService, "info");
jest.spyOn(cipherService, "updateLastUsedDate");
jest.spyOn(chrome.runtime, "sendMessage");
jest.spyOn(eventCollectionService, "collect");
const autofillResult = await autofillService.doAutoFill(autofillOptions);
@@ -769,7 +769,10 @@ describe("AutofillService", () => {
);
expect(autofillService["generateLoginFillScript"]).toHaveBeenCalled();
expect(logService.info).not.toHaveBeenCalled();
expect(cipherService.updateLastUsedDate).toHaveBeenCalledWith(autofillOptions.cipher.id);
expect(chrome.runtime.sendMessage).toHaveBeenCalledWith({
cipherId: autofillOptions.cipher.id,
command: "updateLastUsedDate",
});
expect(chrome.tabs.sendMessage).toHaveBeenCalledWith(
autofillOptions.pageDetails[0].tab.id,
{
@@ -890,11 +893,11 @@ describe("AutofillService", () => {
it("skips updating the cipher's last used date if the passed options indicate that we should skip the last used cipher", async () => {
autofillOptions.skipLastUsed = true;
jest.spyOn(cipherService, "updateLastUsedDate");
jest.spyOn(chrome.runtime, "sendMessage");
await autofillService.doAutoFill(autofillOptions);
expect(cipherService.updateLastUsedDate).not.toHaveBeenCalled();
expect(chrome.runtime.sendMessage).not.toHaveBeenCalled();
});
it("returns early if the fillScript cannot be generated", async () => {

View File

@@ -463,8 +463,13 @@ export default class AutofillService implements AutofillServiceInterface {
fillScript.properties.delay_between_operations = 20;
didAutofill = true;
if (!options.skipLastUsed) {
await this.cipherService.updateLastUsedDate(options.cipher.id);
// In order to prevent a UI update send message to background script to update last used date
await chrome.runtime.sendMessage({
command: "updateLastUsedDate",
cipherId: options.cipher.id,
});
}
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.

View File

@@ -1142,6 +1142,7 @@ export default class MainBackground {
this.accountService,
lockService,
this.billingAccountProfileStateService,
this.cipherService,
);
this.nativeMessagingBackground = new NativeMessagingBackground(
this.keyService,

View File

@@ -16,6 +16,7 @@ import { MessageListener, isExternalMessage } from "@bitwarden/common/platform/m
import { devFlagEnabled } from "@bitwarden/common/platform/misc/flags";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { NotificationsService } from "@bitwarden/common/platform/notifications";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { CipherType } from "@bitwarden/common/vault/enums";
import { BiometricsCommands } from "@bitwarden/key-management";
@@ -53,6 +54,7 @@ export default class RuntimeBackground {
private accountService: AccountService,
private readonly lockService: LockService,
private billingAccountProfileStateService: BillingAccountProfileStateService,
private cipherService: CipherService,
) {
// onInstalled listener must be wired up before anything else, so we do it in the ctor
chrome.runtime.onInstalled.addListener((details: any) => {
@@ -200,6 +202,9 @@ export default class RuntimeBackground {
case BiometricsCommands.GetBiometricsStatusForUser: {
return await this.main.biometricsService.getBiometricsStatusForUser(msg.userId);
}
case "updateLastUsedDate": {
return await this.cipherService.updateLastUsedDate(msg.cipherId);
}
case "getUseTreeWalkerApiForPageDetailsCollectionFeatureFlag": {
return await this.configService.getFeatureFlag(
FeatureFlag.UseTreeWalkerApiForPageDetailsCollection,