From bb479b0a665a8bf1cb5197267cf1f496e4473503 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 9 May 2024 21:23:40 -0400 Subject: [PATCH] Catch exceptions in API calls for the sake of old Chromium versions Related feedback: https://github.com/uBlockOrigin/uBlock-issues/issues/3217#issuecomment-2103628821 --- platform/chromium/webext.js | 38 ++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/platform/chromium/webext.js b/platform/chromium/webext.js index f044649d61ada..baf83b36c1903 100644 --- a/platform/chromium/webext.js +++ b/platform/chromium/webext.js @@ -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(); + } }); }; };