runet-censorship-bypass/extensions/chromium/minimalistic-pac-setter/extension/20-api-fixes.js

24 lines
570 B
JavaScript

'use strict';
/* `setTimeout` changes context of execution from other window
(e.g. popup) to background window, so we may catch errors
in bg error handlers.
More: https://bugs.chromium.org/p/chromium/issues/detail?id=357568
*/
// Fix error context of methods of all APIs.
for(const api of Object.keys(window.apis)) {
for(const prop of Object.keys(api)) {
if ( typeof(api[prop]) !== 'function' ) {
continue;
}
const method = api[prop];
api[prop] = function(...args) {
setTimeout(method.bind(this, ...args), 0);
};
}
}