Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
355 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 Answer

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将使默认处理程序运行。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...