我正在嘗試適用於Chrome擴展程序的Chrome本機信息API。本機應用程序在Chrome擴展中不起作用
manifest.json的原生應用程序:
{
"name": "app.native",
"description": "Native Message API Test.",
"path": "native.exe",
"type": "stdio",
"allowed_origins": ["chrome-extension://kembignchdjhopkkcolnamikcenaocdm/"]
}
Windows註冊表值:
HKEY_LOCAL_MACHINE\SOFTWARE\Google\Chrome\NativeMessagingHosts\app.native=D:\connectNative\manifest.json
我也試過D:\\\\connectNative\\\\manifest.json
和我添加 「nativeMessaging」 到 「權限」 Chrome擴展程序manifest.json。
生應用CPP:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main(int argc, char* argv[]) {
string input = "";
string message="{\"text\": \"This is a response message\",\"num\": \"three\"}";
unsigned int len = message.length();
cout << char(((len>>0) & 0xFF))
<< char(((len>>8) & 0xFF))
<< char(((len>>16) & 0xFF))
<< char(((len>>24) & 0xFF));
cout << message <<endl;
getline(cin, input);
cout << "You entered: " << input << endl;
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile << input;
myfile.close();
return 0;
}
畢竟是做,我嘗試在我的Chrome擴展:
var testport = chrome.runtime.connectNative('app.native');
testport.onMessage.addListener(function(msg) {
console.log("Received" + msg);
});
testport.onDisconnect.addListener(function() {
console.log("Disconnected");
});
它不能接收任何消息,並始終打印 「斷開連接」。
我試圖連接到一個不存在的應用程序,它仍然打印「斷開」,所以我知道這個本地應用程序沒有配置正確。
任何人都可以指出什麼是錯的或我錯過了什麼?
你沒有說native.exe所在。它在D:\ connectNative \ native.exe中嗎? – sowbug
是的,我嘗試native.exe的相對路徑和絕對路徑,兩者都不起作用。 –
我認爲這個問題是與註冊表項:這是我的.reg文件內容:Windows註冊表編輯器5.00版 [HKEY_LOCAL_MACHINE \ SOFTWARE \谷歌\鍍鉻\ NativeMessagingHosts \ com.windows.screen] @ =「C:\\用戶\\ abc \\桌面\\ Chrome擴展\\ manifest.json「 – rohitvk