From 3bcf0cf4728f3565b4a4e68929efcbfe33fdc69e Mon Sep 17 00:00:00 2001 From: Alex Rickabaugh Date: Tue, 10 Oct 2017 12:57:50 -0700 Subject: [PATCH] fix(service-worker): PushEvent.data has to be decoded (#19764) PushEvent.data is not the data object itself, but an instance representing the data in wire format, with methods to synchronously decode it to JSON, ArrayBuffer, etc. NGSW assumes all push data is in JSON format. PR Close #19764 --- packages/service-worker/worker/src/driver.ts | 2 +- packages/service-worker/worker/testing/scope.ts | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/service-worker/worker/src/driver.ts b/packages/service-worker/worker/src/driver.ts index 7837b45d89..a80b69ede5 100644 --- a/packages/service-worker/worker/src/driver.ts +++ b/packages/service-worker/worker/src/driver.ts @@ -224,7 +224,7 @@ export class Driver implements Debuggable, UpdateSource { } // Handle the push and keep the SW alive until it's handled. - msg.waitUntil(this.handlePush(msg.data)); + msg.waitUntil(this.handlePush(msg.data.json())); } private async handleMessage(msg: MsgAny&{action: string}, from: Client): Promise { diff --git a/packages/service-worker/worker/testing/scope.ts b/packages/service-worker/worker/testing/scope.ts index bb97a2deaa..2599c04a36 100644 --- a/packages/service-worker/worker/testing/scope.ts +++ b/packages/service-worker/worker/testing/scope.ts @@ -324,7 +324,10 @@ class MockMessageEvent extends MockExtendableEvent { } class MockPushEvent extends MockExtendableEvent { - constructor(readonly data: Object) { super(); } + constructor(private _data: Object) { super(); } + data = { + json: () => this._data, + }; } class MockInstallEvent extends MockExtendableEvent {}