diff --git a/src/index.js b/src/index.js index ed2cdcd17390..fb99c7e4d4b7 100644 --- a/src/index.js +++ b/src/index.js @@ -58,13 +58,18 @@ export class PostmsgTransport { if(!e.data || typeof(e.data) !== 'string') { return; } + let data; try { - const { key, event } = JSON.parse(e.data); - if (key === this._key) { - this._handler(event); - } + data = JSON.parse(e.data); } catch (e) { return null; } + if(!data || typeof(data) !== 'object') { + return null; + } + const { key, event } = data; + if (key === this._key) { + this._handler(event); + } } }