gpt4 book ai didi

javascript - chrome.webNavigation 未定义

转载 作者:数据小太阳 更新时间:2023-10-29 04:24:25 32 4
gpt4 key购买 nike

我正在编写我的第一个 Google 扩展代码,但遇到了一个我一生中从未见过的奇怪错误。

Uncaught TypeError: Cannot read property 'onCompleted' of undefined background.js:4
(anonymous function)

顺便说一句,我是 Javascript 的新手(尽管对 Java 有广泛的了解)。

我的代码是这样的:

chrome.webNavigation.onCompleted.addListener(function(){//error right here
if(hasHostSuffix(document.URL,'mysite.com'))
{
console.log("Web navigation commited!");
var links = document.getElementsByName("a");
for(var i = 0; i < links.length; i++)
{
console.log(links[i].getAttribute("href"));
if(links[i].style.backgroundColor='#272727')
{
links[i].className="gone";
}
}
}
});

我无法找到有关我收到此错误的任何可靠信息。

任何帮助将不胜感激:)

编辑:

我注意到我忘记了一些重要信息 xD 我的 manfiest:

{
"manifest_version": 2,
...,
"permissions": [
"webNavigation"
],
...,
"content_scripts":[
{
"matches":["http://www.mysite.com/*"],
"css":["ur_customstyle.css"],
"js":["background.js"]
}
]
}

最佳答案

在@rsanchez 的回答之上,如果您在扩展程序的后台脚本中调用了 chrome.webNavigation,但仍然出现此错误,您可能还需要添加 webNavigation 权限在您的 manifest.json 中。

"permissions": [
"webNavigation"
]

Mozilla documentation | Chrome Documentation

关于javascript - chrome.webNavigation 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16310958/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com