1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +00:00

Parse web push payload JSON (#13594)

This commit is contained in:
Matt Gibson
2025-02-28 09:53:43 -08:00
committed by GitHub
parent 7da329da45
commit 40f7a0d73f
2 changed files with 13 additions and 2 deletions

View File

@@ -12,7 +12,16 @@ export class NotificationResponse extends BaseResponse {
this.contextId = this.getResponseProperty("ContextId"); this.contextId = this.getResponseProperty("ContextId");
this.type = this.getResponseProperty("Type"); this.type = this.getResponseProperty("Type");
const payload = this.getResponseProperty("Payload"); let payload = this.getResponseProperty("Payload");
if (typeof payload === "string") {
try {
payload = JSON.parse(payload);
} catch {
// guess it was a string
}
}
switch (this.type) { switch (this.type) {
case NotificationType.SyncCipherCreate: case NotificationType.SyncCipherCreate:
case NotificationType.SyncCipherDelete: case NotificationType.SyncCipherDelete:

View File

@@ -124,7 +124,9 @@ class MyWebPushConnector implements WebPushConnector {
return this.webPushApiService.putSubscription(subscription.toJSON()); return this.webPushApiService.putSubscription(subscription.toJSON());
}).pipe( }).pipe(
switchMap(() => this.pushEvent$), switchMap(() => this.pushEvent$),
map((e) => new NotificationResponse(e.data.json().data)), map((e) => {
return new NotificationResponse(e.data.json().data);
}),
); );
}), }),
); );