Skip to content

Commit

Permalink
Merge pull request GoogleChromeLabs#135 from ronhe/guard-smc-parse
Browse files Browse the repository at this point in the history
Wrap JSON.parse with a try...catch block.
  • Loading branch information
surma authored Jun 15, 2018
2 parents 80bc3fc + 0847139 commit 075e820
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion messagechanneladapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ function hookup(
};

smc.addEventListener("message", (event: Event): void => {
const data = JSON.parse((event as MessageEvent).data) as Message;
let data = {} as Message;
try {
data = JSON.parse((event as MessageEvent).data) as Message;
} catch (e) {
return;
}
if (!id) id = data.id;
if (id !== data.id) return;
const mcs = data.messageChannels.map(messageChannel => {
Expand Down

0 comments on commit 075e820

Please sign in to comment.