Browse Source

fix: serialize messages being sent over chrome message ports (#19654)

Shelley Vohr 5 years ago
parent
commit
0289c19a07
1 changed files with 2 additions and 2 deletions
  1. 2 2
      lib/renderer/chrome-api.js

+ 2 - 2
lib/renderer/chrome-api.js

@@ -34,7 +34,7 @@ class Port {
     })
     ipcRenderer.on(`CHROME_PORT_POSTMESSAGE_${portId}`, (event, message) => {
       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)
     })
   }
 
@@ -46,7 +46,7 @@ class Port {
   }
 
   postMessage (message) {
-    ipcRenderer.sendToAll(this.tabId, `CHROME_PORT_POSTMESSAGE_${this.portId}`, message)
+    ipcRenderer.sendToAll(this.tabId, `CHROME_PORT_POSTMESSAGE_${this.portId}`, JSON.stringify(message))
   }
 
   _onDisconnect () {