2019-09-19 16:35:31 +00:00
|
|
|
( function ( track, config, trackSubscribe, user ) {
|
2019-07-16 21:41:37 +00:00
|
|
|
module.exports = function () {
|
2019-09-19 16:35:31 +00:00
|
|
|
var suffix = user.isAnon() ? '.anon' : '.loggedin',
|
2020-07-17 17:48:02 +00:00
|
|
|
// we will keep track of errors counted, so that we don't overcount problematic
|
|
|
|
// browsers/users which are generating multiple issues. See MAX_ERRORS.
|
|
|
|
reportedInThisSession = 0,
|
|
|
|
// Very conservative for now.
|
|
|
|
// After this many errors are tracked, no more will be logged.
|
|
|
|
MAX_ERRORS = 5,
|
2019-09-19 16:35:31 +00:00
|
|
|
COUNTER_NAME = 'counter.MediaWiki.minerva.WebClientError' + suffix;
|
|
|
|
|
2018-08-24 00:34:37 +00:00
|
|
|
/**
|
2020-05-26 11:08:48 +00:00
|
|
|
* Count javascript errors, except for those associated with localStorage
|
|
|
|
* being full or unavailable.
|
2020-06-02 21:21:44 +00:00
|
|
|
*
|
2020-05-26 11:08:48 +00:00
|
|
|
* @param {string} topic name of the event being tracked
|
|
|
|
* @param {Object} data event payload
|
2018-08-24 00:34:37 +00:00
|
|
|
*/
|
2020-05-26 11:08:48 +00:00
|
|
|
function countError( topic, data ) {
|
|
|
|
var isLocalStorage = data && data.source === 'store-localstorage-update';
|
2020-07-17 17:48:02 +00:00
|
|
|
// Some errors, for example the Leaflet "Set map center and zoom first"
|
|
|
|
// error (T257872) can trigger a high volume of client side error reports to the server.
|
|
|
|
// At time of writing 1 IP logged 245 errors in the same session and page and another
|
|
|
|
// logged 3,029 errors across 2 pages. To filter these kind of errors out, set a cap
|
|
|
|
// on the amount of errors that can be logged in a single session.
|
|
|
|
if ( !isLocalStorage && reportedInThisSession < MAX_ERRORS ) {
|
2020-05-26 11:08:48 +00:00
|
|
|
track( COUNTER_NAME, 1 );
|
|
|
|
}
|
2020-07-17 17:48:02 +00:00
|
|
|
reportedInThisSession++;
|
2019-09-19 16:35:31 +00:00
|
|
|
}
|
2019-02-11 18:11:16 +00:00
|
|
|
|
2019-09-19 16:35:31 +00:00
|
|
|
if ( config.get( 'wgMinervaCountErrors' ) ) {
|
|
|
|
// track RL exceptions
|
|
|
|
trackSubscribe( 'resourceloader.exception', countError );
|
|
|
|
// setup the global error handler
|
|
|
|
trackSubscribe( 'global.error', countError );
|
2018-08-24 00:34:37 +00:00
|
|
|
}
|
2019-07-16 21:41:37 +00:00
|
|
|
};
|
2018-09-13 15:33:20 +00:00
|
|
|
}(
|
|
|
|
mw.track,
|
|
|
|
mw.config,
|
|
|
|
mw.trackSubscribe,
|
2019-09-19 16:35:31 +00:00
|
|
|
mw.user
|
2018-09-13 15:33:20 +00:00
|
|
|
) );
|