如果我们旁边有html和JavaScript代码,并且我的JavaScript中有未定义的变量,我可以在Firefox开发工具(F12)中看到错误。 现在我正在开发扩展程序,但在任何地方都看不到错误。
我在this link中读过有关设置扩展开发环境的信息,但这对我没有帮助。
我在stackoverflow中看到类似的问题,但是它们并没有帮助我。
<html>
<p id='p1' onclick='add()'>1</p>
<script>
function add(){
p1 = document.getElementById('p1')
p1.innerText++
}
observer = new MutationObserver(function(mutations){
console.log(mutations)
});
observer.observe(p1,{
childList :true
});
</script>
</html>
在这种情况下,如果我写的是p2而不是p1,我在DevTools Console中会看到类似:Uncaught RefrenceError ...
但是如果我使用javascript代码作为扩展名,则无法调试或看到错误
p1 = document.getElementById('p1')
observer = new MutationObserver(function(mutations){
console.log(mutations)
});
observer.observe(p1,{
childList :true
});
我的扩展目标是跟踪页面中的更改并记录它们。 但是我在扩展工具的DevTool控制台中看不到错误。
编辑: 问题是当我加载扩展程序时,调试器为空。(我看不到我的js文件)
为什么?
答案 0 :(得分:0)
您需要先修复JavaScript。
1-使用var,let,const声明变量(也最好使用;可以通过搜索Google阅读“ JavaScript最佳实践”来关闭代码)
const p1 = document.getElementById('p1');
2- ++用于数字,而p1的内容是文本,例如。 '1'
3-您必须将值重新分配给元素
这是一个示例:
function add(){
const p1 = document.getElementById('p1');
p1.textContent = parseInt(p1.textContent) +1;
}
您正在使用哪个调试器?
您是否去过about:debugging
-> This Nightly
->您的分机号-> inspect
?