javascript - 在 background.js 中使用 chrome.runtime.connectNative() 获取错误
问题描述
我正在为 chrome 编写扩展(版本 77.0.3865.90),在尝试在 background.js 中使用 chrome.runtime.connectNative() 后出现错误“ Uncaught TypeError: chrome.runtime.connectNative is not a function ”,这很困惑我,因为我没有在 content.js 中使用它。此功能是否已弃用?
清单.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
}
背景.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;
}
解决方案
推荐阅读
- javascript - 脚本陷入循环 3-5 次然后停止
- firebase - 如何在单个 Firebase 数据库中为多个应用构建推送令牌
- python - 我可以在表单提交时动态生成 python 函数吗?
- machine-learning - 特征选择算法可以与包含分类值的列一起使用吗?
- java - JavaFX TableView 在通过 Button 编辑时表现奇怪
- sql-server - Crystal Reports 可以访问表,但不能访问视图
- javascript - 使用 JavaScript 在对象内嵌套一个数组
- c++ - 多项式系数代码始终提供相同的答案
- windows-10 - 在 Windows 10 中捕获屏幕锁定/解锁事件
- flutter - 如何在颤动中创建水平和垂直可滚动的小部件