1
我想創建火狐webextension,即用一個簡單的C++應用程序溝通,我想將消息發送到C++應用程序,並收到一個簡單的消息(你好世界的例子) 。webextension原生應用程序C++的Hello World
現在,這是我做了什麼:
的manifest.json(webextension)
{
"manifest_version": 2,
"name": "nameofwebextension",
"version": "1.0",
"description": "test",
"permissions": [
"tabs",
"activeTab",
"downloads",
"downloads.open",
"nativeMessaging"
],
"icons": {
"48": "icons/border-48.png"
},
"content_scripts": [
{
"matches": ["http://www.testwebsite.com/*"],
"js": ["content.js"]
}
],
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_icon": "icons/beasts-32.png",
"default_title": "test",
"default_popup": "popup/test.html",
"browser_style": false
},
"applications": {
"gecko": {
"id": "[email protected]",
"strict_min_version": "50.0"
}
}
}
background.js
var port = browser.runtime.connectNative("nameofapp");
console.log("Sending: ping");
port.postMessage("ping");
port.onMessage.addListener((response) => {
console.log("Received: " + response);
});
manifest.json的(C++應用程序)
{
"name": "nameofapp",
"description": "Example host for native messaging",
"path": "bin/Debug/nameofapp.exe",
"type": "stdio",
"allowed_extensions": [ "[email protected]" ]
}
的main.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
//cin.get();
return 0;
}
我也在註冊表編輯器中創建了正確的鍵。
這是我進入瀏覽器控制檯:
Sending: ping
Native application tried to send a message of 1819043144 bytes,
which exceeds the limit of 1048576 bytes.