From 6d5e49478269d38cb494edfb5df51541e19adaf5 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Mon, 15 Jul 2019 03:05:09 -0700 Subject: [PATCH] fix: serialize messages being sent over chrome message ports (#19104) Chrome appears to serialize these messages (see #19070) so we should as well to be consistent and to avoid bugs with Uint8/16 arrays Fixes #19070 --- lib/renderer/chrome-api.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/renderer/chrome-api.ts b/lib/renderer/chrome-api.ts index f2c8db613951..ad07f7c2c6d4 100644 --- a/lib/renderer/chrome-api.ts +++ b/lib/renderer/chrome-api.ts @@ -40,10 +40,10 @@ class Port { }) ipcRendererInternal.on(`CHROME_PORT_POSTMESSAGE_${portId}`, ( - _event: Electron.Event, message: string + _event: Electron.Event, message: any ) => { const sendResponse = function () { console.error('sendResponse is not implemented') } - this.onMessage.emit(message, this.sender, sendResponse) + this.onMessage.emit(JSON.parse(message), this.sender, sendResponse) }) } @@ -54,8 +54,8 @@ class Port { this._onDisconnect() } - postMessage (message: string) { - ipcRendererInternal.sendToAll(this.tabId, `CHROME_PORT_POSTMESSAGE_${this.portId}`, message) + postMessage (message: any) { + ipcRendererInternal.sendToAll(this.tabId, `CHROME_PORT_POSTMESSAGE_${this.portId}`, JSON.stringify(message)) } _onDisconnect () {