I have a script that detects Javascript errors on my website and sends them to my backend for reporting.(我有一个脚本,可以检测网站上的Javascript错误并将其发送到我的后端进行报告。)
It reports the first error encountered, the supposed line number, and the time.(它报告遇到的第一个错误,假定的行号和时间。)
EDIT to include doctype:(编辑以包含doctype:)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" xmlns:fb="http://www.facebook.com/2008/fbml">
...(...)
<script type="text/javascript">
//<![CDATA[
// for debugging javascript!
(function(window){
window.onerror = function(msg, url, ln) {
//transform errors
if (typeof(msg) === 'object' && msg.srcElement && msg.target) {
if(msg.srcElement == '[object HTMLScriptElement]' && msg.target == '[object HTMLScriptElement]'){
msg = 'Error loading script';
}else{
msg = 'Event Error - target:' + msg.target + ' srcElement:' + msg.srcElement;
}
}
msg = msg.toString();
//ignore errors
if(msg.indexOf("Location.toString") > -1){
return;
}
if(msg.indexOf("Error loading script") > -1){
return;
}
//report errors
window.onerror = function(){};
(new Image()).src = "/jserror.php?msg=" + encodeURIComponent(msg) + "&url=" + encodeURIComponent(url || document.location.toString().replace(/#.*$/, "")) + "&ln=" + parseInt(ln || 0) + "&r=" + (+new Date());
};
})(window);
//]]>
</script>
Because of this script, I'm acutely aware of any javascript errors that are happening on my site.(由于有了这个脚本,我很清楚自己的网站上发生的任何JavaScript错误。)
One of by biggest offenders is "Script Error."(最大的违规者之一是“脚本错误”。) on line 0. in Chrome 10+, and Firefox 3+.(在Chrome 10以上版本和Firefox 3以上版本中, 位于第0行 。) This error doesn't exist (or may be called something else?) in Internet Explorer.(此错误在Internet Explorer中不存在(或可能称为其他错误?)。)
Correction (5/23/2013): This "Script Error, Line 0" error is now showing up in IE7 and possibly other versions of IE.(更正(5/23/2013):此“脚本错误,第0行”错误现在在IE7和其他版本的IE中显示。)
Possibly a result of a recent IE security patch as this behavior previously did not exist.(可能是由于最近的IE安全修补程序引起的,因为以前没有此行为。)
Does anyone have any idea what this error means or what causes it?(有谁知道这个错误是什么意思或者是什么原因导致的?)
It happens on about 0.25% of my overall pageloads, and represents half the reported errors.(它发生在我的总网页加载量的0.25%左右,占报告的错误的一半。)
ask by Mike Sherov translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…