easonwong-de / Adaptive-Tab-Bar-Colour

Changes the colour of Firefox tab bar to match the website theme.
https://addons.mozilla.org/firefox/addon/adaptive-tab-bar-colour/
MIT License
310 stars 11 forks source link

Ignore all theme color option sometimes uses theme color anyway while the page loads #41

Closed Freeplayg closed 1 year ago

Freeplayg commented 1 year ago

I probably should have made an issue about this earlier, but I've noticed that while the page loads (or just for a few seconds), the theme color is used for a few or split seconds, then ignores that color afterwards

With sites with brighter theme colors, it can be kind of jarring having it flash like that

easonwong-de commented 1 year ago

Hello! @Freeplayg. I actually know it happens and why it happens (see below, optional).

A content script is used to extract a webpage’s theme colour. But, the script is newly loaded when a new page is opened, which means every time a new page is opened, the script has to read the user’s preference to decide if the theme-color tag should be ignored.

I was concerned about that’ll cause a slight delay between a new page being opened and tab bar colour being applied, so the content script reads and sends the colour of the page to the background script using default settings (using theme-color tag) as soon as the page is loaded. At the same time, the background script detects that a new page is opened, and sends the actual user’s preferences to the content script.

That’s why you’re noticing the flash. In that split moment of flash, after the content script has sent the colour to the background script, the content script hasn’t received the user’s preferences yet. And when the content script receives the user’s preferences, it reads the colour of the page again and new tab bar colour is applied.

I think I can change the content script a bit. Immediacy might be forfeited a little, but stability can be improved.

easonwong-de commented 1 year ago

Moreover, to avoid flashing, you can also turn off “Allow light/dark tab bar”, which is closer to Safari’s behaviour on macOS. Safari prevents its tab bar from showing jarring colour by giving the tab bar its default colour during the webpage is being loaded & when the webpage returns a contrastive colour.

easonwong-de commented 1 year ago

@Freeplayg I changed how content script works. Settings for ignoring theme-color should be able to load before new tab bar colour being applied.