Can I hide my extension's icon by default?

2019-01-11 21:27发布

问题:

My Chrome extension doesn't need an icon - it's a one-liner extension that doesn't want to take up space on your extension bar.

How can I hide the icon by default?

回答1:

If you don't want an icon, you can omit the browser_action parameter from your manifest.json (the default_icon option is where you usually specify the icon). The browser_action section is what controls what you see in the toolbar.



回答2:

Due to a change spearheaded by Google, all extensions now must have an icon in the toolbar area or the "overflow" in the menu.

Even if you don't have a browser_action, your extension will display an icon (or failing that, a tile with extension name's first letter). If you do not declare a browser_action, it will be greyed out and non-interactive, but will still be there.

The idea of this change is to provide visibility of otherwise potentially stealthy extensions ("Hey user, did you even know you have those installed?"). It's, let's put it, debatable whether it's the best approach, but that was Google's decision.



回答3:

To suppress this behavior, add "converted_from_user_script": true to the extension's manifest.json. This works as of Chrome 61.

It used to be that visiting a link to a user script (ending in .user.js) caused Chrome to package up the user script as a content script extension with a generated manifest which included the converted_from_user_script key. Of course, this no longer works because all extensions (except in developer mode) now have to come from the Chrome Web Store.



回答4:

Google thought it best to make the icon mandatory and I think so too, for reasons already pointed out by Xan.

Now of course you 're right, when you say that many extensions have no need for an icon, but the requirement of one still gives your extension an identity and Google still gives the user the opportunity to remove it from the toolbar. He simply has to right click the extension's icon and then choose Hide in Chrome menu.

I know, many users don't really bother to read all of the options under right click, or even right click it at all. But most of them still will make a single left click, to see if there is any option in the fancy new extension they added. You can take advantage of this by making a simple window where you point out their option of hiding the icon.