开发者

Google Chrome uncaught javascript exception

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.


It's because chrome://newtab expects certain elements to be there (for JavaScript purposes) but you're wiping them out by using document.body.innerHTML. You could inject an element to use for your output instead, something like this should work:

var cnt = 0;
document.body.innerHTML = '<div id="abcd">...</div>' + document.body.innerHTML;

(function(){
    document.getElementById('abcd').innerHTML=cnt;
    window.setTimeout(arguments.callee,100);
})();

(function(){ cnt++;window.setTimeout(arguments.callee,0); })();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜