gpt4 book ai didi

google-chrome-extension - 带有 Electron 应用程序的Chrome Native Messaging

转载 作者:行者123 更新时间:2023-12-03 12:21:43 29 4
gpt4 key购买 nike

我正在尝试在Chrome扩展程序和OSX上的 Electron 应用程序之间建立通信。

我在~/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.company.app.json中有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"]
}

在chrome扩展程序上,我有一个简单的本地消息传递调用:
chrome.runtime.sendNativeMessage('com.company.app',
{ text: "Hello" },
function(response) {
console.log("Received " + response);
});

然后在main.development.js中,我有:
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);
})

但是,当我执行 sendNativeMessage时,我在日志中看不到任何内容。我在这里想念什么吗?

最佳答案

最近偶然发现了这个问题,发现在Windows平台中不支持从主线程访问stdin和stdio。通过在我的 Electron 应用程序中启动http服务器并从Windows平台的http端口监听,可以暂时使它正常工作。

但是,在MAC OS上也应如此,只需使用electronic-packager构建您的 Electron 应用程序,然后在path变量中给出exe( Electron 应用程序的exe)的路径,如下所示。

{
"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"]
}

为了使其在Windows中正常工作,请参阅此帖子,它可能有解决方案,

GitHub -Issue of stdin and stdio in electron application

关于google-chrome-extension - 带有 Electron 应用程序的Chrome Native Messaging,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42256410/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com