Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome extension development: Disable browser action

Is it possible to set the browser action button disabled? or cancel the popup when a condition is true?

Bob

like image 808
Thomas Andersen Avatar asked Nov 06 '11 14:11

Thomas Andersen


People also ask

What is the difference between browser action and page action?

Page actions represent actions that can be taken on the current page, but that aren't applicable to all pages. Page actions appear grayed out when inactive. Like browser actions, page actions can have an icon, a tooltip, and popup; they can't have badges, however. In addition, page actions can be grayed out.

What is a browser action extension?

A browser action is a button that your extension adds to the browser's toolbar. The button has an icon, and may optionally have a popup whose content is specified using HTML, CSS, and JavaScript.

What is the action button on Chrome?

browserAction. Use browser actions to put icons in the main Google Chrome toolbar, to the right of the address bar. In addition to its icon, a browser action can have a tooltip, a badge, and a popup.


2 Answers

You can remove popup body with:

chrome.browserAction.setPopup({popup: ""});

and switch icon to disabled with:

chrome.browserAction.setIcon({path: "icon-disabled.png"});

To enable, you would need to run those methods again with corresponding params.

like image 143
serg Avatar answered Sep 29 '22 14:09

serg


You can set it disable with following code:

chrome.browserAction.enable(integer tabId);

You find more information in the Chrome Apis:

http://developer.chrome.com/extensions/browserAction.html#method-disable

like image 42
ArrayMaster Avatar answered Sep 29 '22 14:09

ArrayMaster