Edit: I didn't see the post had be edited to take account for the suggestion. Due to how old the thread is, it's possible it won't work due to Manifest V3.
Here's an alternative implementation method:
In your manifest.json, you can use the
theme: property.Specify the icons as 2 separate icon sets and specify them under "icons" in your manifest (e.g.):
icon-light-16.png, icon-light-48.png, icon-light-128.png for the light mode icons.
icon-dark-16.png, icon-dark-48.png, icon-dark-128.png for the dark mode icons.
From there, for MV3 you can update the icon dynamically using
chrome.action.setIcon, with a sample implementation such as:
chrome.action.setIcon({
path: {
"16": {
light: "icon-light-16.png",
dark: "icon-dark-16.png"
},
"48": {
light: "icon-light-48.png",
dark: "icon-dark-48.png"
},
"128": {
light: "icon-light-128.png",
dark: "icon-dark-128.png"
}
}
});
From there, you can use a addListener, but slightly different (see the Action documentation from before):
chrome.action.onThemeChanged.addListener(({ theme }) => {
chrome.action.setIcon({
path: {
"16": {
light: "icon-light-16.png",
dark: "icon-dark-16.png"
},
"48": {
light: "icon-light-48.png",
dark: "icon-dark-48.png"
},
"128": {
light: "icon-light-128.png",
dark: "icon-dark-128.png"
}
}
});
});
This should work for what you're trying to do.
Cheers,
Deco