在background.js中使用chrome.runtime.connectNative()获取错误

时间:2019-10-02 02:48:57

标签: javascript google-chrome-extension background

我正在为chrome(版本77.0.3865.90)编写扩展程序,尝试使用chrome.runtime后收到错误消息“ 未捕获的TypeError:chrome.runtime.connectNative不是函数”。 background.js中的connectNative()令我感到困惑,因为我没有在content.js中使用它。此功能已弃用吗?

manifest.json

{
    "name": "Muter",
    "version": "0.1",
    "description": "Mute html5 video with shortkey.",
    "permissions": ["declarativeContent", "storage", "tabs", "http://*/*", "https://*/"],
    "background": {
        "scripts": ["background.js"],
        "persistent": true
    },
    "page_action": {
        "default_popup": "popup.html"
    },
    "content_scripts": [
        {
            "matches": ["<all_urls>"],
            "js": ["content.js"],
            "run_at": "document_end"
        }
    ],
    "commands": {
        "pause" : {
            "suggested_key": {
                "mac": "Command+Shift+Z"
            },
            "description": "Pause video"
        }
    },
    "manifest_version": 2
}

background.js

var videoStack = [];
var isVideoPlaying = true;
var port = chrome.runtime.connectNative('video_controler');

port.onMessage.addListener((response) => {
    console.log('Received: ' + response);
});


主机应用


#include <stdio.h>

int main(void)
{
    printf("pause_or_play\n");
    return 0;
}

0 个答案:

没有答案