Prevent spurious error messages to browser console

These spurious error messages can occur when a
extension framework API method return a
rejected Promise. In uBO the results of
browserAction methods is not used so it can be
safely discarded.
This commit is contained in:
Raymond Hill 2019-09-23 09:29:17 -04:00
parent 1c72b171de
commit 733b2330de
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 48 additions and 3 deletions

View File

@ -602,7 +602,7 @@ vAPI.Tabs = class {
/******************************************************************************/
/******************************************************************************/
if ( browser.windows instanceof Object ) {
if ( webext.windows instanceof Object ) {
vAPI.windows = {
get: async function() {
let win;
@ -637,6 +637,52 @@ if ( browser.windows instanceof Object ) {
/******************************************************************************/
/******************************************************************************/
if ( webext.browserAction instanceof Object ) {
vAPI.browserAction = {
setTitle: async function() {
try {
await webext.browserAction.setTitle(...arguments);
}
catch (reason) {
}
},
};
// Not supported on Firefox for Android
if ( webext.browserAction.setIcon ) {
vAPI.browserAction.setBadgeTextColor = async function() {
try {
await webext.browserAction.setBadgeTextColor(...arguments);
}
catch (reason) {
}
};
vAPI.browserAction.setBadgeBackgroundColor = async function() {
try {
await webext.browserAction.setBadgeBackgroundColor(...arguments);
}
catch (reason) {
}
};
vAPI.browserAction.setBadgeText = async function() {
try {
await webext.browserAction.setBadgeText(...arguments);
}
catch (reason) {
}
};
vAPI.browserAction.setIcon = async function() {
try {
await webext.browserAction.setIcon(...arguments);
}
catch (reason) {
}
};
}
}
/******************************************************************************/
/******************************************************************************/
// Must read: https://code.google.com/p/chromium/issues/detail?id=410868#c8
// https://github.com/chrisaljoudi/uBlock/issues/19
@ -652,7 +698,7 @@ if ( browser.windows instanceof Object ) {
// Ensure ImageData for toolbar icon is valid before use.
vAPI.setIcon = (( ) => {
const browserAction = webext.browserAction;
const browserAction = vAPI.browserAction;
const titleTemplate =
browser.runtime.getManifest().browser_action.default_title +
' ({badge})';

View File

@ -59,7 +59,6 @@ const promisify = function(thisArg, fnName) {
const webext = {
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/browserAction
browserAction: {
onClicked: chrome.browserAction.onClicked,
setBadgeBackgroundColor: promisifyNoFail(chrome.browserAction, 'setBadgeBackgroundColor'),
setBadgeText: promisifyNoFail(chrome.browserAction, 'setBadgeText'),
setIcon: promisifyNoFail(chrome.browserAction, 'setIcon'),