1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-01 02:02:29 +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 fn = thisArg[fnName];
return function() {
return function(...args) {
return new Promise(resolve => {
fn.call(thisArg, ...arguments, function() {
if ( chrome.runtime.lastError instanceof Object ) {
void chrome.runtime.lastError.message;
}
resolve(outFn(...arguments));
});
try {
fn.call(thisArg, ...args, function(...args) {
void chrome.runtime.lastError;
resolve(outFn(...args));
});
} catch(ex) {
console.error(ex);
resolve(outFn());
}
});
};
};
const promisify = function(thisArg, fnName) {
const fn = thisArg[fnName];
return function() {
return function(...args) {
return new Promise((resolve, reject) => {
fn.call(thisArg, ...arguments, function() {
const lastError = chrome.runtime.lastError;
if ( lastError instanceof Object ) {
return reject(lastError.message);
}
resolve(...arguments);
});
try {
fn.call(thisArg, ...args, function(...args) {
const lastError = chrome.runtime.lastError;
if ( lastError instanceof Object ) {
return reject(lastError.message);
}
resolve(...args);
});
} catch(ex) {
console.error(ex);
resolve();
}
});
};
};