Skip to content

Commit

Permalink
Catch exceptions in API calls for the sake of old Chromium versions
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed May 10, 2024
1 parent 363ad67 commit bb479b0
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions platform/chromium/webext.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});
};
};
Expand Down

0 comments on commit bb479b0

Please sign in to comment.