'Chrome Native Messaging with electron app
I'm trying to set up communication between a chrome extension and an electron app on OSX.
I have the JSON file in ~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.company.app.json
{
"name": "com.company.app",
"description": "MyApp",
"path": "/Users/johnryan/Desktop/Code/electron-app/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.asar",
"type": "stdio",
"allowed_origins": ["chrome-extension://xxxxxxxxxxxx"]
}
On the chrome extension i have a simple native messaging call:
chrome.runtime.sendNativeMessage('com.company.app',
{ text: "Hello" },
function(response) {
console.log("Received " + response);
});
then in the main.development.js i have:
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
rl.on('line', function(line){
console.log("RECEIVED:" + line);
})
However, when i execute the sendNativeMessage I don't see anything in the logs. Is there something i'm missing here?
Solution 1:[1]
Recently stumbled upon this issue, and found out that in windows platform access to stdin and stdio from main thread is not supported. Temporarily I have made it work by starting the http server inside my electron application and listening from http port in windows platform.
However the same should work on MAC OS just build your electron application using electron-packager and give path of your exe(exe of your electron app) in the path variable, as given below.
{
"name": "com.company.app",
"description": "MyApp",
"path": "/Users/johnryan/Desktop/Code/electron-app/node_modules/electron/dist/Electron.app/Contents/Resources/default_app.exe",
"type": "stdio",
"allowed_origins": ["chrome-extension://xxxxxxxxxxxx"]
}
In order for it to work in windows see this post it might have a solution,
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Todd |
