谷歌浏览器未捕获 JavaScript 异常
在 Firefox 4.0 或 Internet Explorer 8+ 中不会发生此错误。
我创建一个新的空选项卡,然后打开控制台(Ctrl+Shift+I,然后 Esc)并粘贴以下代码:
var cnt = 0;
(function() {document.body.innerHTML = cnt;window.setTimeout(arguments.callee,100);})();
(function(){cnt++;window.setTimeout(arguments.callee,0);})();
有时此时会出现错误,但并非总是如此。
之后我粘贴更多内容:
(function(){cnt++;window.setTimeout(arguments.callee,0);})();
大约 30 秒后,我收到以下错误:
未捕获类型错误:无法读取 null 的属性“offsetHeight”
未捕获的类型错误:无法读取 null 的属性“classList”
问题:问题是什么?我该如何解决这个问题?
更新:
当我在打开的选项卡之间切换时会发生此错误,但也是随机的。
This error does not happen in Firefox 4.0 or Internet Explorer 8+.
I create a new empty tab, and open console (Ctrl+Shift+I and then Esc) and paste the following codes:
var cnt = 0;
(function() {document.body.innerHTML = cnt;window.setTimeout(arguments.callee,100);})();
(function(){cnt++;window.setTimeout(arguments.callee,0);})();
Sometimes there is an error at this point but not always.
After this I paste more:
(function(){cnt++;window.setTimeout(arguments.callee,0);})();
After ~30sec I get any of these errors:
Uncaught TypeError: Cannot read property 'offsetHeight' of null
Uncaught TypeError: Cannot read property 'classList' of null
The question: what is the problem? How can I solve this?
UPDATE:
This error happens when I switch between my opened tabs, but also randomly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为
chrome://newtab
期望某些元素存在(出于 JavaScript 目的),但您使用document.body.innerHTML
删除了它们。您可以注入一个元素用于输出,类似这样的东西应该可以工作:It's because
chrome://newtab
expects certain elements to be there (for JavaScript purposes) but you're wiping them out by usingdocument.body.innerHTML
. You could inject an element to use for your output instead, something like this should work: