【发布时间】:2019-03-28 17:51:30
【问题描述】:
当尝试使用 Chrome 的 WebNavigation.onCompleted 在某个 url 上运行 background.js 时,我收到错误 “未捕获的 TypeError:无法添加侦听器”。 对于 manifest.json 中的权限,我已授予对 activetab 和 webrequest 的扩展访问权限。
我尝试过使用其他监听器,例如 chrome.browserAction.onClicked.addListener 它工作得很好。我也在使用最新版本的 chrome (v73)。
背景.js:
chrome.webNavigation.onCompleted.addListener(function(tab) {
var eurl = tab.url.split("/skill/");
if(eurl[0] === "https://www.duolingo.com") {
chrome.tabs.executeScript(tab.ib, {
file: 'jquery-3.3.1.min.js'
});
chrome.tabs.executeScript(tab.ib, {
file: 'duohelperinjector.js'
});}
}, {url: [{urlMatches : '*://duolingo.com/skill/*'}]});
manifest.json:
{
"name": "DuoHelper",
"version": "0.0.1",
"manifest_version": 2,
"description": "A Chrome Extension That Helps With Duolingo",
"homepage_url": "https://github.com/TechHax/DuoHelper",
"background": {
"scripts": [
"background.js"
],
"persistent": true
},
"browser_action": {
"default_title": "DuoHelper"
},
"permissions": [
"webNavigation",
"activeTab"
]
}
我得到的错误:
未捕获的类型错误:无法添加侦听器
如果扩展程序正常工作,我希望 chrome 扩展程序在其 url 为 *://duolingo.com/skill/* 的活动选项卡上注入 javascript 文件。
【问题讨论】:
标签: javascript google-chrome-extension