Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
300 views
in Technique[技术] by (71.8m points)

javascript - 捕获所有JavaScript错误并将其发送到服务器(Catch all JavaScript errors and send them to server)

I wondered if anyone had experience in handling JavaScript errors globally and send them from the client browser to a server.

(我想知道是否有人有全局处理JavaScript错误的经验,并将它们从客户端浏览器发送到服务器。)

I think my point is quite clear, I want to know every exception, error, compilation error, etc. that happens on the client side and send them to the server to report them.

(我认为我的观点很清楚,我想知道客户端发生的每个异常,错误,编译错误等,并将它们发送到服务器进行报告。)

I'm mainly using MooTools and head.js (for the JS side) and Django for the server side.

(我主要使用MooTools和head.js (对于JS方面)和Django用于服务器端。)

  ask by Olivier Girardot translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'd check out window.onerror

(我看看window.onerror)

Example:

(例:)

window.onerror = function(message, url, lineNumber) {  
  //save error and send to server for example.
  return true;
};  

Keep in mind that returning true will prevent the firing of the default handler, and returning false will let the default handler run.

(请记住,返回true将阻止触发默认处理程序,返回false将使默认处理程序运行。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...