Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为什么内容脚本在2次重新加载后不继续执行?_Javascript_Google Chrome_Google Chrome Extension_Google Chrome Devtools - Fatal编程技术网

Javascript 为什么内容脚本在2次重新加载后不继续执行?

Javascript 为什么内容脚本在2次重新加载后不继续执行?,javascript,google-chrome,google-chrome-extension,google-chrome-devtools,Javascript,Google Chrome,Google Chrome Extension,Google Chrome Devtools,我在www.frikitrivial.com上做了一个“永远赢”的扩展。所有的机制都在内容脚本文件中,每次选项卡的url等于“”时,它都必须重新加载页面,但在这样做2次之后,它停止,我的意思是,内容脚本不再执行。我在脚本的开头写了一个console.log()来检查这个问题 谢谢 这是内容脚本文件中的代码(您可以忽略其中的大部分) console.log(“Iniciando partida…”) 让我们提问,回答,回答 如果(location.href!==”http://www.friki

我在www.frikitrivial.com上做了一个“永远赢”的扩展。所有的机制都在内容脚本文件中,每次选项卡的url等于“”时,它都必须重新加载页面,但在这样做2次之后,它停止,我的意思是,内容脚本不再执行。我在脚本的开头写了一个console.log()来检查这个问题

谢谢

这是内容脚本文件中的代码(您可以忽略其中的大部分)

console.log(“Iniciando partida…”)
让我们提问,回答,回答
如果(location.href!==”http://www.frikitrivial.com/end.php" ){
question=document.querySelectorAll(“div.question”)[0]。textContent
答案=[]
_答案=document.querySelectorAll(“a.answer”)
document.querySelectorAll(“a.answer”).forEach(e=>answers.push(e.textContent))
}
功能点击{
让c
for(设i=0;i<4;i++){
如果(s===你回答[i].textContent){
c=_答案[i]
}
}
console.log(“El siguiente elemento va ser clickado…”)
控制台日志(c)
c、 单击()
}
chrome.storage.sync.get([“lastClicked”],函数(结果){
如果(result.lastClicked){
log(“Leido lastClicked…”)
如果(location.href==”http://www.frikitrivial.com/end.php”{//manejamos fallo
控制台日志(“Manejando fallo de pregunta…”)
chrome.storage.sync.set({
[结果.上次单击.问题]:{
问题:result.lastclacked.question,
答案:result.lastClicked.answers.shift(),
回答:错
}
},()=>chrome.runtime.sendMessage({redirect:https://www.frikitrivial.com/game.php"}))
}其他{//
如果(!result.lastClicked.answered){
log(“Manejando lastClicked未回答…”)
chrome.storage.sync.set({
[结果.上次单击.问题]:{
问题:result.lastclacked.question,
答案:result.lastClicked.answers,
回答:是的
}
},回答(新问题)
}否则{
log(“Manejando…”)
回答新问题()
}
}
}否则{
回答新问题()
}
})
函数回答新问题(){
chrome.storage.sync.get([问题],函数(结果){
如果(result.question){//si ya hemos intentado responder esta pregunta alguna vez
如果(结果、问题、答案){
chrome.storage.sync.set({
[结果.问题]:{
问题:result.question.question,
答案:result.question.answers,
回答:result.question.answered
}
},()=>单击(结果.问题.答案[0]))
}否则{
chrome.storage.sync.set({
上次单击:{
问题:result.question.question,
答案:result.question.answers,
回答:result.question.answered
}
},()=>单击(结果.问题.答案[0]))
}
}否则{
chrome.storage.sync.set({
[问题]:{
问题:问题:,
答案:答案,,
回答:错
}
},函数(结果){
chrome.storage.sync.set({
上次单击:{
问题:问题:,
答案:答案,,
回答:错
}
},()=>单击(答案[0]))
})
}
})  

}
我喜欢通过注释掉除了console.log语句之外的几乎整个文件,然后运行它来调试这类问题,只是为了确认问题与文件本身的内容无关。您没有显示manifest.json,所以我不得不猜测第三次会发生什么。1) 可能URL不同,它与manifest.json中的
“matches”
不匹配。2) 也许页面正在通过历史API使用“软”导航,或者通过更改哈希(URL片段),我将添加它等等!