Skip to content
This repository was archived by the owner on Oct 12, 2021. It is now read-only.

Commit 10484d9

Browse files
committed
feat(worker): handle text-body push messages (e.g. from devtools)
1 parent 852778a commit 10484d9

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

service-worker/worker/src/plugins/push/index.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,23 @@ export class PushImpl implements Plugin<PushImpl> {
6464
}
6565

6666
push(data: any): void {
67-
this.maybeShowNotification(data);
67+
let message: any;
68+
try {
69+
message = JSON.parse(data);
70+
} catch (e) {
71+
// If the string can't be parsed, display it verbatim.
72+
message = {
73+
notification: {
74+
title: data,
75+
},
76+
};
77+
}
78+
this.maybeShowNotification(message);
6879
if (this.buffer !== null) {
69-
this.buffer.push(data);
80+
this.buffer.push(message);
7081
} else {
7182
this.streams.forEach(id => {
72-
this.worker.sendToStream(id, data);
83+
this.worker.sendToStream(id, message);
7384
})
7485
}
7586
}

service-worker/worker/src/worker/driver.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,10 @@ export class Driver {
280280
}
281281

282282
Promise
283-
// Wait for both initialization and the JSON data sent with the push message.
283+
// Wait for both initialization and the data sent with the push message.
284284
.all([
285285
this.init,
286-
event.data.json(),
286+
event.data.text(),
287287
])
288288
// Result of this.init is unimportant as long as it's resolved.
289289
.then(results => results[1])

0 commit comments

Comments
 (0)