Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Web Push Support #11346

Open
wants to merge 54 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
df8ac40
WIP: PoC with lots of terrible code with web push
MGibson1 Aug 6, 2024
4952f03
fix service worker building
MGibson1 Aug 26, 2024
1b5a0e9
Work on WebPush Tailored to Browser
justindbaur Sep 12, 2024
99cf6a3
Clean Up Web And MV2
justindbaur Sep 13, 2024
b00dd2f
Merge remote-tracking branch 'origin/main' into web-push-poc
justindbaur Sep 30, 2024
dce334e
Fix Merge Conflicts
justindbaur Sep 30, 2024
2998144
Prettier
justindbaur Sep 30, 2024
c49dca0
Use Unsupported for MV2
justindbaur Sep 30, 2024
95d2577
Add Doc Comments
justindbaur Oct 1, 2024
6e85ab0
Remove Permission Button
justindbaur Oct 1, 2024
a614989
Merge remote-tracking branch 'origin/main' into web-push-poc
justindbaur Oct 1, 2024
57752d6
Fix Type Test
justindbaur Oct 1, 2024
3802bb6
Write Time In More Readable Format
justindbaur Oct 2, 2024
71d9b4f
Add SignalR Logger
justindbaur Oct 2, 2024
ec8f22f
Merge remote-tracking branch 'origin/main' into web-push-poc
justindbaur Oct 2, 2024
bf215e8
Merge remote-tracking branch 'origin/main' into web-push-poc
justindbaur Oct 14, 2024
5c276b1
`sheduleReconnect` -> `scheduleReconnect`
justindbaur Oct 17, 2024
bf1d596
Capture Support Context In Connector
justindbaur Oct 17, 2024
2a81514
Remove Unneeded CSP Change
justindbaur Oct 22, 2024
9c65fc7
Fix Build
justindbaur Oct 22, 2024
cf427cb
Simplify `getOrCreateSubscription`
justindbaur Oct 22, 2024
2b267ef
Add More Docs to Matrix
justindbaur Oct 22, 2024
ae42d4d
Update libs/common/src/platform/notifications/internal/worker-webpushโ€ฆ
justindbaur Oct 24, 2024
847a18c
Move API Service Into Notifications Folder
justindbaur Oct 24, 2024
1e51ca8
Merge branch 'web-push-poc' of https://github.com/bitwarden/clients iโ€ฆ
justindbaur Oct 24, 2024
265ff51
Merge remote-tracking branch 'origin/main' into web-push-poc
justindbaur Oct 24, 2024
cec35ea
Allow Connection When Account Is Locked
justindbaur Oct 28, 2024
72dfc1f
Add Comments to NotificationsService
justindbaur Oct 30, 2024
71e6ea1
Only Change Support Status If Public Key Changes
justindbaur Oct 31, 2024
a351664
Move Service Choice Out To Method
justindbaur Oct 31, 2024
37e2eff
Use Named Constant For Disabled Notification Url
justindbaur Oct 31, 2024
a4f8bb9
Merge remote-tracking branch 'origin/main' into web-push-poc
justindbaur Nov 19, 2024
340f56b
Add Test & Cleanup
justindbaur Nov 19, 2024
4b2ad4f
Flatten
justindbaur Nov 19, 2024
4df0dec
Move Tests into `beforeEach` & `afterEach`
justindbaur Nov 20, 2024
ac47da4
Add Tests
justindbaur Nov 20, 2024
516f004
Merge remote-tracking branch 'origin/main' into web-push-poc
justindbaur Nov 20, 2024
98076cf
Test `distinctUntilChanged`'s Operators More
justindbaur Nov 21, 2024
20c49e8
Make Helper And Cleanup Chain
justindbaur Nov 21, 2024
351906a
Merge remote-tracking branch 'origin/main' into web-push-poc
justindbaur Nov 21, 2024
0a49496
Add Back Cast
justindbaur Nov 21, 2024
d4efd2a
Add extra safety to incoming config check
justindbaur Dec 16, 2024
ef370da
Put data through response object
justindbaur Dec 16, 2024
65997ef
Merge remote-tracking branch 'origin/main' into web-push-poc
justindbaur Dec 16, 2024
c23b886
Apply TS Strict Rules
justindbaur Dec 17, 2024
8de29d8
Finish PushTechnology comment
justindbaur Dec 17, 2024
b395841
Use `instanceof` check
justindbaur Dec 17, 2024
d9ee535
Do Safer Worker Based Registration for MV3
justindbaur Dec 18, 2024
be83877
Remove TODO
justindbaur Dec 18, 2024
d74b544
Switch to SignalR on any WebPush Error
justindbaur Dec 18, 2024
8a20d13
Merge remote-tracking branch 'origin/main' into web-push-poc
justindbaur Dec 26, 2024
dcc4729
Fix Manifest Permissions
justindbaur Dec 26, 2024
3a1bd25
Add Back `webNavigation`
justindbaur Dec 26, 2024
57c6eec
Sorry, Remove `webNavigation`
justindbaur Dec 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/browser/src/background/idle.background.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { firstValueFrom } from "rxjs";

import { NotificationsService } from "@bitwarden/common/abstractions/notifications.service";
import { VaultTimeoutSettingsService } from "@bitwarden/common/abstractions/vault-timeout/vault-timeout-settings.service";
import { VaultTimeoutService } from "@bitwarden/common/abstractions/vault-timeout/vault-timeout.service";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { VaultTimeoutAction } from "@bitwarden/common/enums/vault-timeout-action.enum";
import { NotificationsService } from "@bitwarden/common/platform/notifications";
import { VaultTimeoutStringType } from "@bitwarden/common/types/vault-timeout.type";

const IdleInterval = 60 * 5; // 5 minutes
Expand Down
53 changes: 31 additions & 22 deletions apps/browser/src/background/main.background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import { AuditService as AuditServiceAbstraction } from "@bitwarden/common/abstractions/audit.service";
import { EventCollectionService as EventCollectionServiceAbstraction } from "@bitwarden/common/abstractions/event/event-collection.service";
import { EventUploadService as EventUploadServiceAbstraction } from "@bitwarden/common/abstractions/event/event-upload.service";
import { NotificationsService as NotificationsServiceAbstraction } from "@bitwarden/common/abstractions/notifications.service";
import { SearchService as SearchServiceAbstraction } from "@bitwarden/common/abstractions/search.service";
import { VaultTimeoutSettingsService as VaultTimeoutSettingsServiceAbstraction } from "@bitwarden/common/abstractions/vault-timeout/vault-timeout-settings.service";
import { InternalOrganizationServiceAbstraction } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
Expand Down Expand Up @@ -107,6 +106,13 @@
import { Account } from "@bitwarden/common/platform/models/domain/account";
import { GlobalState } from "@bitwarden/common/platform/models/domain/global-state";
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
import { NotificationsService } from "@bitwarden/common/platform/notifications";
import {

Check warning on line 110 in apps/browser/src/background/main.background.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/background/main.background.ts#L110

Added line #L110 was not covered by tests
DefaultNotificationsService,
WorkerWebPushConnectionService,
SignalRConnectionService,
UnsupportedWebPushConnectionService,
} 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";
Expand All @@ -124,6 +130,7 @@
import { KeyGenerationService } from "@bitwarden/common/platform/services/key-generation.service";
import { MigrationBuilderService } from "@bitwarden/common/platform/services/migration-builder.service";
import { MigrationRunner } from "@bitwarden/common/platform/services/migration-runner";
import { DefaultWebPushNotificationsApiService } from "@bitwarden/common/platform/services/notifications/web-push-notifications-api.service";

Check warning on line 133 in apps/browser/src/background/main.background.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/background/main.background.ts#L133

Added line #L133 was not covered by tests
import { DefaultSdkService } from "@bitwarden/common/platform/services/sdk/default-sdk.service";
import { NoopSdkClientFactory } from "@bitwarden/common/platform/services/sdk/noop-sdk-client-factory";
import { StateService } from "@bitwarden/common/platform/services/state.service";
Expand Down Expand Up @@ -156,7 +163,6 @@
import { AuditService } from "@bitwarden/common/services/audit.service";
import { EventCollectionService } from "@bitwarden/common/services/event/event-collection.service";
import { EventUploadService } from "@bitwarden/common/services/event/event-upload.service";
import { NotificationsService } from "@bitwarden/common/services/notifications.service";
import { SearchService } from "@bitwarden/common/services/search.service";
import { VaultTimeoutSettingsService } from "@bitwarden/common/services/vault-timeout/vault-timeout-settings.service";
import {
Expand Down Expand Up @@ -303,7 +309,7 @@
importService: ImportServiceAbstraction;
exportService: VaultExportServiceAbstraction;
searchService: SearchServiceAbstraction;
notificationsService: NotificationsServiceAbstraction;
notificationsService: NotificationsService;
stateService: StateServiceAbstraction;
userNotificationSettingsService: UserNotificationSettingsServiceAbstraction;
autofillSettingsService: AutofillSettingsServiceAbstraction;
Expand Down Expand Up @@ -366,6 +372,8 @@
kdfConfigService: kdfConfigServiceAbstraction;
offscreenDocumentService: OffscreenDocumentService;
syncServiceListener: SyncServiceListener;

webPushConnectionService: WorkerWebPushConnectionService | UnsupportedWebPushConnectionService;
themeStateService: DefaultThemeStateService;
autoSubmitLoginBackground: AutoSubmitLoginBackground;
sdkService: SdkService;
Expand Down Expand Up @@ -394,11 +402,6 @@
constructor(public popupOnlyContext: boolean = false) {
// Services
const lockedCallback = async (userId?: string) => {
if (this.notificationsService != null) {
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.notificationsService.updateConnection(false);
}
await this.refreshBadge();
await this.refreshMenu(true);
if (this.systemService != null) {
Expand Down Expand Up @@ -1033,17 +1036,27 @@
this.organizationVaultExportService,
);

this.notificationsService = new NotificationsService(
this.logService,
if (BrowserApi.isManifestVersion(3)) {
this.webPushConnectionService = new WorkerWebPushConnectionService(

Check warning on line 1040 in apps/browser/src/background/main.background.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/background/main.background.ts#L1040

Added line #L1040 was not covered by tests
this.configService,
new DefaultWebPushNotificationsApiService(this.apiService, this.appIdService),
(self as unknown as { registration: ServiceWorkerRegistration }).registration,
);
} else {
this.webPushConnectionService = new UnsupportedWebPushConnectionService();

Check warning on line 1046 in apps/browser/src/background/main.background.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/background/main.background.ts#L1046

Added line #L1046 was not covered by tests
}

this.notificationsService = new DefaultNotificationsService(

Check warning on line 1049 in apps/browser/src/background/main.background.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/background/main.background.ts#L1049

Added line #L1049 was not covered by tests
this.syncService,
this.appIdService,
this.apiService,
this.environmentService,
logoutCallback,
this.stateService,
this.authService,
this.messagingService,
this.taskSchedulerService,
this.accountService,
new SignalRConnectionService(this.apiService, this.logService),
this.authService,
this.webPushConnectionService,
this.logService,
);

this.fido2UserInterfaceService = new BrowserFido2UserInterfaceService(this.authService);
Expand Down Expand Up @@ -1265,6 +1278,9 @@
}

async bootstrap() {
if ("start" in this.webPushConnectionService) {
JaredSnider-Bitwarden marked this conversation as resolved.
Show resolved Hide resolved
this.webPushConnectionService.start();

Check warning on line 1282 in apps/browser/src/background/main.background.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/background/main.background.ts#L1282

Added line #L1282 was not covered by tests
}
this.containerService.attachToGlobal(self);

// Only the "true" background should run migrations
Expand Down Expand Up @@ -1348,12 +1364,7 @@
setTimeout(async () => {
await this.refreshBadge();
await this.fullSync(true);
this.taskSchedulerService.setInterval(
ScheduledTaskNames.scheduleNextSyncInterval,
5 * 60 * 1000, // check every 5 minutes
);
setTimeout(() => this.notificationsService.init(), 2500);
await this.taskSchedulerService.verifyAlarmsState();
this.notificationsService.startListening();

Check warning on line 1367 in apps/browser/src/background/main.background.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/background/main.background.ts#L1367

Added line #L1367 was not covered by tests
resolve();
}, 500);
});
Expand Down Expand Up @@ -1432,7 +1443,6 @@
ForceSetPasswordReason.None;

await this.systemService.clearPendingClipboard();
await this.notificationsService.updateConnection(false);

if (nextAccountStatus === AuthenticationStatus.LoggedOut) {
this.messagingService.send("goHome");
Expand Down Expand Up @@ -1536,7 +1546,6 @@
}
await this.refreshBadge();
await this.mainContextMenuHandler?.noAccess();
await this.notificationsService.updateConnection(false);
await this.systemService.clearPendingClipboard();
await this.systemService.startProcessReload(this.authService);
}
Expand Down
3 changes: 1 addition & 2 deletions apps/browser/src/background/runtime.background.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { firstValueFrom, map, mergeMap } from "rxjs";

import { LockService } from "@bitwarden/auth/common";
import { NotificationsService } from "@bitwarden/common/abstractions/notifications.service";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { AutofillOverlayVisibility, ExtensionCommand } from "@bitwarden/common/autofill/constants";
import { AutofillSettingsServiceAbstraction } from "@bitwarden/common/autofill/services/autofill-settings.service";
Expand All @@ -12,6 +11,7 @@ import { MessagingService } from "@bitwarden/common/platform/abstractions/messag
import { SystemService } from "@bitwarden/common/platform/abstractions/system.service";
import { devFlagEnabled } from "@bitwarden/common/platform/misc/flags";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { NotificationsService } from "@bitwarden/common/platform/notifications";
import { CipherType } from "@bitwarden/common/vault/enums";

import { MessageListener, isExternalMessage } from "../../../../libs/common/src/platform/messaging";
Expand Down Expand Up @@ -215,7 +215,6 @@ export default class RuntimeBackground {
await closeUnlockPopout();
}

await this.notificationsService.updateConnection(msg.command === "loggedIn");
this.systemService.cancelProcessReload();

if (item) {
Expand Down
3 changes: 2 additions & 1 deletion apps/browser/src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
"alarms",
"webRequest",
"webRequestBlocking",
"webNavigation"
"webNavigation",
"notifications"
],
"optional_permissions": ["nativeMessaging", "privacy"],
"content_security_policy": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'",
Expand Down
3 changes: 2 additions & 1 deletion apps/browser/src/manifest.v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
"offscreen",
"webRequest",
"webRequestAuthProvider",
"webNavigation"
"webNavigation",
"notifications"
],
"optional_permissions": ["nativeMessaging", "privacy"],
"host_permissions": ["https://*/*", "http://*/*"],
Expand Down
2 changes: 1 addition & 1 deletion apps/browser/src/popup/services/services.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import { AnonLayoutWrapperDataService, LockComponentService } from "@bitwarden/auth/angular";
import { LockService, PinServiceAbstraction } from "@bitwarden/auth/common";
import { EventCollectionService as EventCollectionServiceAbstraction } from "@bitwarden/common/abstractions/event/event-collection.service";
import { NotificationsService } from "@bitwarden/common/abstractions/notifications.service";
import { VaultTimeoutService } from "@bitwarden/common/abstractions/vault-timeout/vault-timeout.service";
import { OrganizationService } from "@bitwarden/common/admin-console/abstractions/organization/organization.service.abstraction";
import { PolicyService } from "@bitwarden/common/admin-console/abstractions/policy/policy.service.abstraction";
Expand Down Expand Up @@ -69,6 +68,7 @@
// eslint-disable-next-line no-restricted-imports -- Used for dependency injection
import { SubjectMessageSender } from "@bitwarden/common/platform/messaging/internal";
import { flagEnabled } from "@bitwarden/common/platform/misc/flags";
import { NotificationsService } from "@bitwarden/common/platform/notifications";

Check warning on line 71 in apps/browser/src/popup/services/services.module.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/popup/services/services.module.ts#L71

Added line #L71 was not covered by tests
import { TaskSchedulerService } from "@bitwarden/common/platform/scheduling";
import { ConsoleLogService } from "@bitwarden/common/platform/services/console-log.service";
import { ContainerService } from "@bitwarden/common/platform/services/container.service";
Expand Down
11 changes: 1 addition & 10 deletions apps/desktop/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import { FingerprintDialogComponent } from "@bitwarden/auth/angular";
import { LogoutReason } from "@bitwarden/auth/common";
import { EventUploadService } from "@bitwarden/common/abstractions/event/event-upload.service";
import { NotificationsService } from "@bitwarden/common/abstractions/notifications.service";
import { SearchService } from "@bitwarden/common/abstractions/search.service";
import { VaultTimeoutSettingsService } from "@bitwarden/common/abstractions/vault-timeout/vault-timeout-settings.service";
import { VaultTimeoutService } from "@bitwarden/common/abstractions/vault-timeout/vault-timeout.service";
Expand All @@ -43,6 +42,7 @@
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
import { SystemService } from "@bitwarden/common/platform/abstractions/system.service";
import { clearCaches } from "@bitwarden/common/platform/misc/sequentialize";
import { NotificationsService } from "@bitwarden/common/platform/notifications";

Check warning on line 45 in apps/desktop/src/app/app.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/app/app.component.ts#L45

Added line #L45 was not covered by tests
import { StateEventRunnerService } from "@bitwarden/common/platform/state";
import { SyncService } from "@bitwarden/common/platform/sync";
import { UserId } from "@bitwarden/common/types/guid";
Expand Down Expand Up @@ -209,17 +209,11 @@
this.recordActivity();
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.notificationsService.updateConnection();
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.updateAppMenu();
this.systemService.cancelProcessReload();
break;
case "loggedOut":
this.modalService.closeAll();
if (message.userId == null || message.userId === this.activeUserId) {
await this.notificationsService.updateConnection();
}
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.updateAppMenu();
Expand Down Expand Up @@ -263,9 +257,6 @@
) {
await this.router.navigate(["lock"]);
}
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
// eslint-disable-next-line @typescript-eslint/no-floating-promises
this.notificationsService.updateConnection();
await this.updateAppMenu();
await this.systemService.clearPendingClipboard();
await this.systemService.startProcessReload(this.authService);
Expand Down
6 changes: 3 additions & 3 deletions apps/desktop/src/app/services/init.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import { AbstractThemingService } from "@bitwarden/angular/platform/services/theming/theming.service.abstraction";
import { WINDOW } from "@bitwarden/angular/services/injection-tokens";
import { EventUploadService as EventUploadServiceAbstraction } from "@bitwarden/common/abstractions/event/event-upload.service";
import { NotificationsService as NotificationsServiceAbstraction } from "@bitwarden/common/abstractions/notifications.service";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { TwoFactorService as TwoFactorServiceAbstraction } from "@bitwarden/common/auth/abstractions/two-factor.service";
import { CryptoService as CryptoServiceAbstraction } from "@bitwarden/common/platform/abstractions/crypto.service";
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/platform/abstractions/i18n.service";
import { PlatformUtilsService as PlatformUtilsServiceAbstraction } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { StateService as StateServiceAbstraction } from "@bitwarden/common/platform/abstractions/state.service";
import { NotificationsService } from "@bitwarden/common/platform/notifications";

Check warning on line 15 in apps/desktop/src/app/services/init.service.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/app/services/init.service.ts#L15

Added line #L15 was not covered by tests
import { ContainerService } from "@bitwarden/common/platform/services/container.service";
import { UserAutoUnlockKeyService } from "@bitwarden/common/platform/services/user-auto-unlock-key.service";
import { SyncService as SyncServiceAbstraction } from "@bitwarden/common/platform/sync";
Expand All @@ -32,7 +32,7 @@
private i18nService: I18nServiceAbstraction,
private eventUploadService: EventUploadServiceAbstraction,
private twoFactorService: TwoFactorServiceAbstraction,
private notificationsService: NotificationsServiceAbstraction,
private notificationsService: NotificationsService,
private platformUtilsService: PlatformUtilsServiceAbstraction,
private stateService: StateServiceAbstraction,
private cryptoService: CryptoServiceAbstraction,
Expand Down Expand Up @@ -68,7 +68,7 @@
await (this.i18nService as I18nRendererService).init();
(this.eventUploadService as EventUploadService).init(true);
this.twoFactorService.init();
setTimeout(() => this.notificationsService.init(), 3000);
this.notificationsService.startListening();

Check warning on line 71 in apps/desktop/src/app/services/init.service.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/app/services/init.service.ts#L71

Added line #L71 was not covered by tests
const htmlEl = this.win.document.documentElement;
htmlEl.classList.add("os_" + this.platformUtilsService.getDeviceString());
this.themingService.applyThemeChangesTo(this.document);
Expand Down
Loading
Loading