Expose/Document Theme Color Computation

I’ve noticed a challenge when trying to give my extension a native firefox look. It seems that Firefox uses some sort of internal color computation for browser.themes that isn’t accessible to developers. This is an issue when trying to exactly match native popup colors, especially when trying to match the hover-colors.

What I’ve Found:

  • With the native Dark theme, the native popup background is #42414d, which matches browser.theme.color.popup.
  • But with Alpenglow, the native popup is #2d245b, even though browser.theme.color.popup reports #281d4e.
  • For custom themes, I managed to recreate the correct hover color by mixing browser.theme.color.popup with browser.theme.color.popup_text at 16.86% opacity (when both are greyscale).
  • Mixing the native Dark theme popup color with the popup_text does not produce the same color in the native popup as in my own extension—unless I create a custom theme using the dark theme’s popup (#42414d) and popup_text (#fbfbfe) values at which point they match.

This suggests that Firefox might be processing native themes a bit differently than custom themes. Either way, this obscurity may be by design to protect against misuse, or more likely just to improve contrast, but it makes it tough to get things right (essentially impossible) when trying to design an accessible extension that matches the users browser theme.

What I’d Love to See:

  1. An API to Get the Computed Colors:
    An API function that returns the pre-mixed colors. That way, extensions could match the system theme exactly.
  2. Some Docs on the Process:
    If exposing an API is too much, maybe Mozilla could at least document the blending algorithm. This would help us mirror the behavior on our end.

I’m curious if anyone else has run into this or if Mozilla has any plans to open up these details. Thanks for any thoughts or suggestions!

What do you mean when you say that #42414d “matches browser.theme.color.popup”?

Something could just be escaping me at the moment, but I can only think of two ways for an add-on to interact with theme values: using browser.theme.getCurrent() and CSS’s keywords. Is browser.theme.color.popup shorthand for something like this?

(await browser.theme.getCurrent()).color.popup;

Anyway, back to your questions. There are a couple of open bugs related to styling extensions based on the browser theme:

IMO it’s currently prohibitively difficult for an extension to match the user’s selected browser theme. While theme.getCurrent() allows extensions to get light theme colors, if the theme supports both light and dark modes, the getCurrent() method will only return the light theme values. That’s … not ideal.