Permalink
Browse files

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
  • Loading branch information...
alxhub authored and tbosch committed Oct 10, 2017
1 parent 396c241 commit 3bcf0cf4728f3565b4a4e68929efcbfe33fdc69e
Showing with 5 additions and 2 deletions.
  1. +1 −1 packages/service-worker/worker/src/driver.ts
  2. +4 −1 packages/service-worker/worker/testing/scope.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<void> {
@@ -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 {}

0 comments on commit 3bcf0cf

Please sign in to comment.