I've tried searching for this, and the closest related question that I could find was from 3+ years ago and had to do with the incognito window being dark, while a normal chrome window was light back then.
Now that we have the ability to have a light or dark mode browser, it's hard to find an icon design and color that looks good for both light and dark modes. Here's an example:
In the image above you can see that the first and third icons are black, so they are hard to see when using dark-mode. The middle icon (the one I'm using for my extension)looks great on dark mode, but terrible on light mode. See below:
So does anyone know if there is there a way to detect the browser mode (light or dark) and swap out the icon?
Thanks to wOxxOm I was able to figure this out.
First, I needed to create a content script (which I called toggleIcon.js
) and add it to the manifist.json file
.
Then I added the following to toggleIcon.js
- which sends scheme: "dark"
to my background.js file if window.matchMedia
matches prefers-color-scheme: dark
.
Then in my background.js
file I listen for that message, and if request.scheme == "dark"
I use chrome.broserAction.setIcon
to change the paths for each of my icons to the dark version.
This effectively overrides my original icon paths as declared in the manifest.json
file (as shown below).
The only downside I see is that this requires a content_script
, which if you want your extension to work on any page, requires you to also add "matches": ["<all_urls>"]
to your extension, which slows down the approval process. Which is why in my comments above I mentioned I had been avoiding using a content_script.
Also, I think it makes sense to use the version of your icons that work best on light-mode as your default, because I think the chrome extension page will pull from these for some of the icons they use (and that page has a white background). As an example, here's how my old icon looked (not enough contrast).
Hopefully this helps someone else!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With