Native messaging host
Chrome 扩展
{
"name": "AppName",
"description": "",
"version": "1.0",
"manifest_version": 3,
"permissions": [
"nativeMessaging" // ? https://developer.chrome.com/docs/extensions/mv3/declare_permissions/
]
// ...
}
主机
添加架构
@echo off
:: If you add "/f" then you can force write.
REG ADD "HKCU\Software\Google\Chrome\NativeMessagingHosts\com.my_company.my_application" ^
/ve /t REG_SZ ^
/d "%~dp0Mymanifest.json"
// Mymanifest.json
{
"name": "com.my_company.my_application",
"description": "My Application",
"path": "relative_dir/my.exe",
"type": "stdio",
"allowed_origins": [
"chrome-extension://nbjjflbnekmabedahdolabcpahfjojjb/"
]
}
chrome.runtime.sendNativeMessage
示例:
// your.js
chrome.runtime.sendNativeMessage("com.my_company.my_application",
{key1: "value1", key2: "value2"}, // ? Send those parameters to your program.
(response) => {
console.log(response)
}
)
示例存储库
我创建了一个项目thunder/e11fde9,其最终目标是能够使用浏览器作为输入,然后在本地打开指定的文件(如果可能,不用鼠标)
它仍在开发中,但我认为早期的代码已经足够了。链接如下。
其中已经有记录浏览器传输结果的日志,同时浏览器也可以获取程序的返回值。
参考