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
This commit is contained in:
Alex Rickabaugh 2017-10-10 12:57:50 -07:00 committed by Tobias Bosch
parent 396c2417d9
commit 3bcf0cf472
2 changed files with 5 additions and 2 deletions

View File

@ -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> {

View File

@ -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 {}