Skip to content

Commit

Permalink
fix: serialize messages being sent over chrome message ports (#19252)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
trop[bot] authored and codebytere committed Jul 16, 2019
1 parent fb51509 commit 019e605
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/renderer/chrome-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,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)
})
}

Expand All @@ -55,8 +55,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 () {
Expand Down

0 comments on commit 019e605

Please sign in to comment.