没有找到谷歌扩展本地消息传递主机
Google extensions Native messaging host not found
本地消息有问题。
当我尝试连接本地应用程序时,我得到这个错误:
Connecting to native messaging host com.google.chrome.example.echo
Failed to connect: Specified native messaging host not found.
第一个本机应用c#
static void Main(string[] args)
{
string message = "test message from native app.";
OpenStandardStreamOut(message);
while (OpenStandardStreamIn() != null || OpenStandardStreamIn() != "")
{
OpenStandardStreamOut("Received to Native App: " + OpenStandardStreamIn());
OpenStandardStreamOut("Recieved: " + OpenStandardStreamIn());
}
Console.WriteLine("END");
}
private static string OpenStandardStreamIn()
{
//// We need to read first 4 bytes for length information
Stream stdin = Console.OpenStandardInput();
int length = 0;
byte[] bytes = new byte[4];
stdin.Read(bytes, 0, 4);
length = System.BitConverter.ToInt32(bytes, 0);
string input = "";
for (int i = 0; i < length; i++)
{
input += (char)stdin.ReadByte();
}
return input;
}
private static void OpenStandardStreamOut(string stringData)
{
//// We need to send the 4 btyes of length information
string msgdata = "{'"text'":'"" + stringData + "'"}";
int DataLength = msgdata.Length;
Stream stdout = Console.OpenStandardOutput();
stdout.WriteByte((byte)((DataLength >> 0) & 0xFF));
stdout.WriteByte((byte)((DataLength >> 8) & 0xFF));
stdout.WriteByte((byte)((DataLength >> 16) & 0xFF));
stdout.WriteByte((byte)((DataLength >> 24) & 0xFF));
//Available total length : 4,294,967,295 ( FF FF FF FF )
Console.Write(msgdata);
}
,这是manifest。
{
"name": "com.my_company.my_application",
"description": "Native messaging host",
"path": "C:''Documents and Settings''xx xx''Moje dokumenty''Visual Studio 2010''Projects''KomunikacjaChrome''KomunikacjaChrome''bin''Debug''KomunikacjaChrome.exe",
"type": "stdio",
"allowed_origins": [
"chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/"
]
}
这是如何chrome扩展:
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
var port = null;
var getKeys = function(obj){
var keys = [];
for(var key in obj){
keys.push(key);
}
return keys;
}
function appendMessage(text) {
document.getElementById('response').innerHTML += "<p>" + text + "</p>";
}
function updateUiState() {
if (port) {
document.getElementById('connect-button').style.display = 'none';
document.getElementById('input-text').style.display = 'block';
document.getElementById('send-message-button').style.display = 'block';
} else {
document.getElementById('connect-button').style.display = 'block';
document.getElementById('input-text').style.display = 'none';
document.getElementById('send-message-button').style.display = 'none';
}
}
function sendNativeMessage() {
message = {"text": document.getElementById('input-text').value};
port.postMessage(message);
appendMessage("Sent message: <b>" + JSON.stringify(message) + "</b>");
}
function onNativeMessage(message) {
appendMessage("Received message: <b>" + JSON.stringify(message) + "</b>");
}
function onDisconnected() {
appendMessage("Failed to connect: " + chrome.runtime.lastError.message);
port = null;
updateUiState();
}
function connect() {
var hostName = "com.google.chrome.example.echo";
appendMessage("Connecting to native messaging host <b>" + hostName + "</b>")
port = chrome.runtime.connectNative(hostName);
port.onMessage.addListener(onNativeMessage);
port.onDisconnect.addListener(onDisconnected);
updateUiState();
}
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('connect-button').addEventListener(
'click', connect);
document.getElementById('send-message-button').addEventListener(
'click', sendNativeMessage);
updateUiState();
});
和清单。
{
// Extension ID: knldjmfmopnpolahpmmgbagdohdnhkik
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDcBHwzDvyBQ6bDppkIs9MP4ksKqCMyXQ/A52JivHZKh4YO/9vJsT3oaYhSpDCE9RPocOEQvwsHsFReW2nUEc6OLLyoCFFxIb7KkLGsmfakkut/fFdNJYh0xOTbSN8YvLWcqph09XAY2Y/f0AL7vfO1cuCqtkMt8hFrBGWxDdf9CQIDAQAB",
"name": "Native Messaging Example",
"version": "1.0",
"manifest_version": 2,
"description": "Send a message to a native application.",
"app": {
"launch": {
"local_path": "main.html"
}
},
"icons": {
"128": "icon-128.png"
},
"permissions": [
"nativeMessaging"
]
}
html <html>
<head>
<script src='./main.js'></script>
</head>
<body>
<button id='connect-button'>Connect</button>
<input id='input-text' type='text' />
<button id='send-message-button'>Send</button>
<div id='response'></div>
</body>
</html>
我还添加了manifest。json (c#)到regedit
HKEY_LOCAL_MACHINE ' SOFTWARE '谷歌' ' NativeMessagingHosts ' com.my_company铬。my_application
和
HKEY_CURRENT_USER ' SOFTWARE '谷歌Chrome ' NativeMessagingHosts ' ' com.my_company.my_application
C:'Documents and Settings'xx xx'Moje dokumenty'Visual Studio 2010'Projects'KomunikacjaChrome'KomunikacjaChrome'bin'Debug'manifest.json
我忘记什么了吗?我想我已经迈出了所有的步骤,但还是不行。
谢谢你的帮助!
编辑
我解决了这个问题,在main.js我没有添加端口
var port = chrome.runtime.connectNative('com.my_company.my_application');
我解决了这个问题,在main.js中我没有添加端口
var port = chrome.runtime.connectNative('com.my_company.my_application');
相关文章:
- 为什么我得到Chrome本机消息“;找不到指定的本机消息传递主机&”;
- 消息传递系统 jquery 发送jQuery514109241_1210239812938当我在消息中放入:))时
- 有没有一种简单的转换方法可以将chrome消息传递转换为safari消息传递语法
- 消息传递接收端
- 基本的谷歌chrome扩展消息传递不起作用
- Chrome 扩展消息传递体系结构
- 为什么我无法将此消息传递到选项卡中运行的所有帧
- Chrome扩展消息传递:未发送响应
- 为什么在定义回调/侦听器函数(异步消息传递,port.on)后没有立即设置全局变量
- Chrome 消息传递.未捕获错误:连接到扩展时出错
- 在 MQTT 客户端中“未捕获的引用错误:未定义消息传递”
- 用于 SMS 消息传递的 window.location.href - 平台兼容性
- 谷歌打包应用原生消息传递
- 消息传递在 Chrome 19 中断开
- 获取频道中的消息数,而无需在 Twilio IP 消息传递中检索它们
- PHP 和 Jquery 之间的消息传递
- 加载从跨文档消息传递中作为事件数据获得的 pdf
- 跨域消息传递的语法错误
- 没有找到谷歌扩展本地消息传递主机
- 用于调用外部应用程序的NPAPI替换(本机消息传递主机)无法工作