I'm trying to change the extension icon depending on what is found in the URL, the below works but i get an error:
Uncaught (in promise) TypeError: failureCallback is not a function Context extensions::setIcon Stack Trace
I feel sure this is a woods for the trees thing. Can anyone help?
//get url of the page we are on in the tab
async function getTab() {
let queryOptions = { active: true, currentWindow: true };
let tabs = await chrome.tabs.query(queryOptions);
return tabs[0];
};
var tab;
//listen for the following two events - when they happen run the colourIcon function
chrome.tabs.onActivated.addListener(colourIcon);
chrome.tabs.onUpdated.addListener(colourIcon);
async function colourIcon(){
let urlCol = await getTab()
let url = urlCol.url
tab = urlCol.id
if (url.indexOf("d") > -1) {
changeIconColour("purple");
} else if (url.indexOf("b") > -1) {
changeIconColour("purple");
} else if (url.indexOf("a") > -1) {
changeIconColour("purple");
} else { // if there is no match, you can't get the data
changeIconColour("grey");
};
}
function changeIconColour(colour) {
let pathToIcons;
//change the path to the icon folder depending on what colour is sent to the function
if (colour == "purple") {
pathToIcons = "/";
} else {
pathToIcons = "grey/";
}
// and set the icon
chrome.action.setIcon({
path: {
"16": "/assets/icons" + pathToIcons + "extension_toolbar_icon16.png",
"32": "/assets/icons" + pathToIcons + "extension_toolbar_icon32.png",
"48": "/assets/icons" + pathToIcons + "extension_toolbar_icon48.png",
"128": "/assets/icons" + pathToIcons + "extension_toolbar_icon128.png"
},
tabId: tab
})
};
The error is at extensions::setIcon:35, which is the line starting "failure", here:
$Promise.catch(imageDataPromise, function(error) {
failureCallback(exceptionHandler.safeErrorToString(error, true));
});
It's a bug in Chromium.
Suggests an invalid filepath. But it works.