1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-11 22:03:36 +00:00

fix(browser): restore timer based background syncs (#14031)

* docs: fix a typo

* fix(browser): restore timer-based background syncs

The browser extension was not performing scheduled background syncs every 30 minutes as expected. This was due to missing task scheduling code that was accidentally removed during the web push implementation (PR #11346).

This commit:
- Creates a new BackgroundSyncService to manage sync scheduling
- Properly initializes the sync interval in main.background.ts
- Adds a test to ensure the sync initialization code isn't accidentally removed again
- Organizes platform module structure to support the new service

Fixes PM-19396

* review: remove unecassary await keyword
This commit is contained in:
Addison Beck
2025-03-28 14:17:18 -04:00
committed by GitHub
parent d5f033efa2
commit f759e62aeb
10 changed files with 178 additions and 6 deletions

View File

@@ -0,0 +1,13 @@
// This test skips all the initilization of the background script and just
// focuses on making sure we don't accidently delete the initilization of
// background vault syncing. This has happened before!
describe("MainBackground sync task scheduling", () => {
it("includes code to schedule the sync interval task", () => {
// Get the bootstrap method source code as string
const { default: MainBackground } = jest.requireActual("./main.background");
const bootstrapSource = MainBackground.prototype.bootstrap.toString();
// Check that the source includes the critical sync interval scheduling code
expect(bootstrapSource).toContain("this.backgroundSyncService.init();");
});
});

View File

@@ -127,7 +127,6 @@ import {
WebPushNotificationsApiService,
WorkerWebPushConnectionService,
} from "@bitwarden/common/platform/notifications/internal";
import { ScheduledTaskNames } from "@bitwarden/common/platform/scheduling";
import { AppIdService } from "@bitwarden/common/platform/services/app-id.service";
import { ConfigApiService } from "@bitwarden/common/platform/services/config/config-api.service";
import { DefaultConfigService } from "@bitwarden/common/platform/services/config/default-config.service";
@@ -222,6 +221,7 @@ import {
KdfConfigService,
KeyService as KeyServiceAbstraction,
} from "@bitwarden/key-management";
import { BackgroundSyncService } from "@bitwarden/platform/background-sync";
import {
IndividualVaultExportService,
IndividualVaultExportServiceAbstraction,
@@ -391,6 +391,7 @@ export default class MainBackground {
offscreenDocumentService: OffscreenDocumentService;
syncServiceListener: SyncServiceListener;
browserInitialInstallService: BrowserInitialInstallService;
backgroundSyncService: BackgroundSyncService;
webPushConnectionService: WorkerWebPushConnectionService | UnsupportedWebPushConnectionService;
themeStateService: DefaultThemeStateService;
@@ -585,9 +586,9 @@ export default class MainBackground {
this.logService,
this.stateProvider,
);
this.taskSchedulerService.registerTaskHandler(ScheduledTaskNames.scheduleNextSyncInterval, () =>
this.fullSync(),
);
this.backgroundSyncService = new BackgroundSyncService(this.taskSchedulerService);
this.backgroundSyncService.register(() => this.fullSync());
this.environmentService = new BrowserEnvironmentService(
this.logService,
@@ -1368,6 +1369,7 @@ export default class MainBackground {
setTimeout(async () => {
await this.refreshBadge();
await this.fullSync(false);
this.backgroundSyncService.init();
this.notificationsService.startListening();
resolve();
}, 500);

View File

@@ -29,6 +29,7 @@
"@bitwarden/key-management": ["../../libs/key-management/src"],
"@bitwarden/key-management-ui": ["../../libs/key-management-ui/src"],
"@bitwarden/platform": ["../../libs/platform/src"],
"@bitwarden/platform/*": ["../../libs/platform/src/*"],
"@bitwarden/send-ui": ["../../libs/tools/send/send-ui/src"],
"@bitwarden/tools-card": ["../../libs/tools/card/src"],
"@bitwarden/ui-common": ["../../libs/ui/common/src"],