Skip to content

Commit

Permalink
fix(repl): don't crash from extension messages
Browse files Browse the repository at this point in the history
  • Loading branch information
wmertens committed Nov 14, 2024
1 parent edaa75e commit 84cdc36
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions packages/docs/src/repl/worker/repl-messenger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ import { appUpdate } from './app-update';

export const receiveMessageFromMain = (ev: MessageEvent) => {
if (ev.data) {
const msg: ReplMessage = JSON.parse(ev.data);
if (msg.type === 'update') {
appUpdate(ev.source as any as WindowClient, msg.clientId, msg.options);
try {
const msg: ReplMessage = JSON.parse(ev.data);
if (msg.type === 'update') {
appUpdate(ev.source as any as WindowClient, msg.clientId, msg.options);
}
} catch {
// ignore, probably some extension sending non-JSON data
}
}
};
Expand Down
10 changes: 7 additions & 3 deletions packages/docs/src/repl/worker/repl-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ export const initReplServer = (win: Window, doc: Document, nav: Navigator) => {
return;
}
if (ev.data) {
const msg: ReplMessage = JSON.parse(ev.data);
if (msg?.type === 'event') {
sendMessageToMain(msg);
try {
const msg: ReplMessage = JSON.parse(ev.data);
if (msg?.type === 'event') {
sendMessageToMain(msg);
}
} catch {
// ignore, probably some extension sending non-JSON data
}
}
};
Expand Down

0 comments on commit 84cdc36

Please sign in to comment.