This article mainly introduces window. onerror: the method for capturing and reporting Js errors. if you need a friend, refer to a 2048 game user feedback in the next two days. after opening the game, you cannot play. there is only one game panel, and the number cannot be initialized, even more mobile, the device is iPhone 4 S, iOS 5.1. It is still difficult to enable Safari from startup. Because the game uses a lot of HTML5 features, it is roughly estimated that JS errors are caused. But how can this information be captured? Of course it is the legendary window. onerror.
Find the method body for window. onerror from W3C:
This means that the window. onerror method can be written as follows:
/*** @ Param {String} errorMessage error message * @ param {String} scriptURI error file * @ param {Long} lineNumber error code line number * @ param {Long} columnNumber error code column number * @ param {Object} errorObj error details, anything */window. onerror = function (errorMessage, scriptURI, lineNumber, columnNumber, errobj) {// TODO}
However, you must pay attention to compatibility issues during use. not all browsers have all the parameters in the parameter list. chrome and others are the leading browser standard draft. These parameters are used!
Therefore, you can write a small Demo to try it:
Js error capture