Split out from the general async callback wrapping task as this part proved a lot harder and the upstream code is outdated and not very useful.
See these comments for details.
Split out from the general async callback wrapping task as this part proved a lot harder and the upstream code is outdated and not very useful.
See these comments for details.
Change 195826 had a related patch set uploaded (by Gergő Tisza):
[TEST] Wrap arguments to $.Callbacks.add in try..catch
The easy but invasive way to do this is to replace $.Callbacks.add() (which will affect at least all promise and animation operations in jQuery); the hard but more targeted way is to decorate $.ajax() and modify the promise it returns, but then we also need to modify any promise that returns (via ˙.promise() and .then`), and so on.
Ori suggested that vbench can be used to check the performance penalty of the first version.
A third alternative is to replace the XHR object with a proxy (that is possible via the xhr property of the AJAX options object) and use that to wrap the callback. That's the most targeted of the three approaches, but somewhat fragile as there is no way to detect when properties of the proxy object are changed (ES6 proxies are only supported by Firefox at this time; defineProperty setters only work with known property names and using them on a native object might result in errors; __defineSetter__ is reasonably well-supported (all major browsers except IE 8-10) but non-standard and again might behave unexpectedly on a native object).
The two approaches that seems the most useful for XHR proxying:
Unfortunately this breaks in Chrome. This works as expected:
var xhr = $.ajaxSettings.xhr(); xhr.open( 'GET', '/w/api.php?action=query&format=json&meta=siteinfo', true ); xhr.send(); Object.defineProperty( xhr, 'onreadystatechange', { configurable: true, enumerable:true, value: mw.log, writable: true } );
This does not work, even though inspection shows xhr.onreadystatechange to have the correct value:
var xhr = $.ajaxSettings.xhr(); xhr.open( 'GET', '/w/api.php?action=query&format=json&meta=siteinfo', true ); xhr.send(); Object.defineProperty( xhr, 'onreadystatechange', { configurable: true, enumerable:true, get: $.noop, set: $.noop } ); Object.defineProperty( xhr, 'onreadystatechange', { configurable: true, enumerable:true, value: mw.log, writable: true } );
(reported upstream: #469024)
__defineSetter__ also only works on specified property names; must have confused it with PHP magic functions. So there is no point in using it; defineProperty does the same and has better support.
Change 198178 had a related patch set uploaded (by Gergő Tisza):
Make AJAX callback test harder to pass
Change 198183 had a related patch set uploaded (by Gergő Tisza):
[WIP] Replace XHR in $.ajax with a proxy object with error catching
Discussed with Ori and agreed to abandon this for now, concentrate on the easiest + safest part (window.onerror) and see how much ground that covers. (Originally I believed it to be blocked by the CORS issues but actually for most browsers on most pageviews scripts are loaded from localStorage so there are no cross-domain limitations. And while that won't cover all browsers, or all pageviews on modern browsers, the ones covered will be more valuable than the ones not, due to T90524 and the lack of source map support.)
Change 195826 abandoned by Gergő Tisza:
[TEST] Wrap arguments to $.Callbacks.add in try..catch
Reason:
Abandoning, see T92247 #1147500. Might be revisited later.
Change 198183 abandoned by Gergő Tisza:
[WIP] Replace XHR in $.ajax with a proxy object with error catching
Reason:
Abandoning, see T92247#1147500. Might be revisited later.
At the time of creating this task it was assumed that the server side implementation of error logging would be based on Sentry. We have eventually decided on a different implementation, so de-tagging.
The parent task has been declined, hence also declining this task.
If this task should still be open, then please update its description and associate an active project - thanks!