Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Light & Dark browserAction icons in Chrome 51

In Chrome 51, incognito windows now have a dark toolbar background, while previous versions used a light background. It's generally infeasible for a single 16x16 image to provide good contrast in both situations:

IPvFoo with Light and Dark toolbars

When displaying information to the user through a browserAction icon, by what mechanism can an extension provide dark-themed and light-themed icons, and switch between them depending on the current toolbar color?

Link to source code for the pictured extension

like image 851
Paul Marks Avatar asked Apr 29 '16 06:04

Paul Marks


People also ask

What is light in define?

1a : something that makes vision possible. b : the sensation aroused by stimulation of the visual receptors. c : electromagnetic radiation of any wavelength that travels in a vacuum with a speed of 299,792,458 meters (about 186,000 miles) per second specifically : such radiation that is visible to the human eye.

Does light mean not heavy?

As an adjective, light is something that is not heavy, burdensome, or somber. A knapsack could be light, as could a topic of conversation, or a piece of music.

What is a light in physics?

What is light in physics? Light is electromagnetic radiation that can be detected by the human eye. Electromagnetic radiation occurs over an extremely wide range of wavelengths, from gamma rays with wavelengths less than about 1 × 10−11 metres to radio waves measured in metres.


1 Answers

There is no such simple mechanism (yet), and it sounds like an excellent feature request to make at the very least for the manifest.

It's possible to approximate this though, by detecting incognito tabs being open and replacing the browser action icon for that tab only.

var incognitoIcons = {
  19: "incognito19.png",
  38: "incognito38.png"
};

chrome.tabs.onCreated.addListener(function(tab) {
  if (tab.incognito) {
    chrome.browserAction.setIcon({
      path: incognitoIcons,
      tabId: tab.id
    });
  }
});

If you're using a "split" incognito behavior (non-default), you can simply detect that and change the global icon for the incognito instance:

// Somewhere in background during initialization
if (chrome.extension.inIncognitoContext) {
  chrome.browserAction.setIcon({path: incognitoIcons});
}

Note that content scripts can always rely on inIncognitoContext, so if you trigger a browser action icon change from them you can pass that along.

Obviously, you can do that with imageData instead of path, as is your case.

You may want to check the Chrome version while you're at it; I'm not aware of a better way than mentioned here.

like image 121
Xan Avatar answered Sep 28 '22 11:09

Xan