1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-03 02:37:21 +02:00

Catch exceptions in API calls for the sake of old Chromium versions

Related feedback:
https://github.com/uBlockOrigin/uBlock-issues/issues/3217#issuecomment-2103628821
This commit is contained in:
Raymond Hill 2024-05-09 21:23:40 -04:00
parent 363ad6795c
commit bb479b0a66
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -24,29 +24,37 @@
const promisifyNoFail = function(thisArg, fnName, outFn = r => r) { const promisifyNoFail = function(thisArg, fnName, outFn = r => r) {
const fn = thisArg[fnName]; const fn = thisArg[fnName];
return function() { return function(...args) {
return new Promise(resolve => { return new Promise(resolve => {
fn.call(thisArg, ...arguments, function() { try {
if ( chrome.runtime.lastError instanceof Object ) { fn.call(thisArg, ...args, function(...args) {
void chrome.runtime.lastError.message; void chrome.runtime.lastError;
} resolve(outFn(...args));
resolve(outFn(...arguments)); });
}); } catch(ex) {
console.error(ex);
resolve(outFn());
}
}); });
}; };
}; };
const promisify = function(thisArg, fnName) { const promisify = function(thisArg, fnName) {
const fn = thisArg[fnName]; const fn = thisArg[fnName];
return function() { return function(...args) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
fn.call(thisArg, ...arguments, function() { try {
const lastError = chrome.runtime.lastError; fn.call(thisArg, ...args, function(...args) {
if ( lastError instanceof Object ) { const lastError = chrome.runtime.lastError;
return reject(lastError.message); if ( lastError instanceof Object ) {
} return reject(lastError.message);
resolve(...arguments); }
}); resolve(...args);
});
} catch(ex) {
console.error(ex);
resolve();
}
}); });
}; };
}; };