无法与本机消息传递主机(Firefox)通信

时间:2018-06-28 07:26:41

标签: firefox-addon

因此,使用本机消息传递主机的基本工作流程是

  1. 我们必须将注册表项添加到当前用户或本地计算机,并指定该值作为应用程序清单的路径。

  2. 在清单中指定路径为可执行文件(exe文件或py文件)

  3. 与扩展名和 voila

  4. 通信

所以,我的问题是第一步。我已经在 Chrome 上完成了实施,并且可以无缝运行,但是在 Firefox 上,我无法与主机进行通信。我的直觉是,这与添加注册表项有关,因为我给了与Chrome一起使用的同一个exe文件来发回消息。有人知道我们到底需要添加什么才能使其与Firefox兼容吗?

编辑:(添加我正在使用的文件)

本地消息传递主机清单文件(com.mozilla.firefox.example.echo-win.json)

{
"name": "com.mozilla.firefox.example.echo",
"description": "FireFox Native Messaging API Example Host",
"path": "<path to exe file>",
"type": "stdio",
"allowed_extensions": ["moz-extension://<Internal UUID>/"]
}

扩展清单文件(manifest.json)

{
    "manifest_version": 2,
    "name": <name>,    
    "version": "1.0",    
    "description": <description>,    
    "permissions": ["activeTab",  "storage", "nativeMessaging"],    
    "background": {
        "scripts": ["background.js"]
    },    
    "applications": {
        "gecko": {
            "id": "examplelol@example.com",
            "strict_min_version": "50.0"
        }
    },    
    "content_scripts": [{
        "matches": ["*://localhost/*"],
        "js":["content.js"]}],    
    "icons": {
        <default icon paths and sizes>
    },
}

我用于本机消息传递主机的注册表命令是

REG ADD "HKCU\SOFTWARE\Mozilla\NativeMessagingHosts\com.mozilla.firefox.example.echo" /ve /t REG_SZ /d "%~dp0com.mozilla.firefox.example.echo-win.json" /f

1 个答案:

答案 0 :(得分:0)

的默认值 HKLM SOFTWARE\Mozilla\NativeMessagingHosts\com.mozilla.firefox.example.echo 应该具有com.mozilla.firefox.example.echo-win.json文件的完整路径的值。因此,您的reg命令似乎正确。

在这里,您的格式也可能不正确-就我们所使用的ID而言,而不是其他moz ext格式。 "allowed_extensions": ["<Internal UUID>","ID2"]