Dart Documentationchrome.browserActionChromeBrowserAction

ChromeBrowserAction class

class ChromeBrowserAction extends ChromeApi {
 static final JsObject _browserAction = chrome['browserAction'];

 ChromeBrowserAction._();

 bool get available => _browserAction != null;

 /**
  * Sets the title of the browser action. This shows up in the tooltip.
  */
 void setTitle(BrowserActionSetTitleParams details) {
   if (_browserAction == null) _throwNotAvailable();

   _browserAction.callMethod('setTitle', [jsify(details)]);
 }

 /**
  * Gets the title of the browser action.
  */
 Future<String> getTitle(BrowserActionGetTitleParams details) {
   if (_browserAction == null) _throwNotAvailable();

   var completer = new ChromeCompleter<String>.oneArg();
   _browserAction.callMethod('getTitle', [jsify(details), completer.callback]);
   return completer.future;
 }

 /**
  * Sets the icon for the browser action. The icon can be specified either as
  * the path to an image file or as the pixel data from a canvas element, or as
  * dictionary of either one of those. Either the <b>path</b> or the
  * <b>imageData</b> property must be specified.
  */
 Future setIcon(BrowserActionSetIconParams details) {
   if (_browserAction == null) _throwNotAvailable();

   var completer = new ChromeCompleter.noArgs();
   _browserAction.callMethod('setIcon', [jsify(details), completer.callback]);
   return completer.future;
 }

 /**
  * Sets the html document to be opened as a popup when the user clicks on the
  * browser action's icon.
  */
 void setPopup(BrowserActionSetPopupParams details) {
   if (_browserAction == null) _throwNotAvailable();

   _browserAction.callMethod('setPopup', [jsify(details)]);
 }

 /**
  * Gets the html document set as the popup for this browser action.
  */
 Future<String> getPopup(BrowserActionGetPopupParams details) {
   if (_browserAction == null) _throwNotAvailable();

   var completer = new ChromeCompleter<String>.oneArg();
   _browserAction.callMethod('getPopup', [jsify(details), completer.callback]);
   return completer.future;
 }

 /**
  * Sets the badge text for the browser action. The badge is displayed on top
  * of the icon.
  */
 void setBadgeText(BrowserActionSetBadgeTextParams details) {
   if (_browserAction == null) _throwNotAvailable();

   _browserAction.callMethod('setBadgeText', [jsify(details)]);
 }

 /**
  * Gets the badge text of the browser action. If no tab is specified, the
  * non-tab-specific badge text is returned.
  */
 Future<String> getBadgeText(BrowserActionGetBadgeTextParams details) {
   if (_browserAction == null) _throwNotAvailable();

   var completer = new ChromeCompleter<String>.oneArg();
   _browserAction.callMethod('getBadgeText', [jsify(details), completer.callback]);
   return completer.future;
 }

 /**
  * Sets the background color for the badge.
  */
 void setBadgeBackgroundColor(BrowserActionSetBadgeBackgroundColorParams details) {
   if (_browserAction == null) _throwNotAvailable();

   _browserAction.callMethod('setBadgeBackgroundColor', [jsify(details)]);
 }

 /**
  * Gets the background color of the browser action.
  */
 Future<ColorArray> getBadgeBackgroundColor(BrowserActionGetBadgeBackgroundColorParams details) {
   if (_browserAction == null) _throwNotAvailable();

   var completer = new ChromeCompleter<ColorArray>.oneArg(_createColorArray);
   _browserAction.callMethod('getBadgeBackgroundColor', [jsify(details), completer.callback]);
   return completer.future;
 }

 /**
  * Enables the browser action for a tab. By default, browser actions are
  * enabled.
  * 
  * [tabId] The id of the tab for which you want to modify the browser action.
  */
 void enable([int tabId]) {
   if (_browserAction == null) _throwNotAvailable();

   _browserAction.callMethod('enable', [tabId]);
 }

 /**
  * Disables the browser action for a tab.
  * 
  * [tabId] The id of the tab for which you want to modify the browser action.
  */
 void disable([int tabId]) {
   if (_browserAction == null) _throwNotAvailable();

   _browserAction.callMethod('disable', [tabId]);
 }

 /**
  * Opens the extension popup window in the active window but does not grant
  * tab permissions.
  * 
  * Returns:
  * JavaScript 'window' object for the popup window if it was succesfully
  * opened.
  */
 Future<Map<String, dynamic>> openPopup() {
   if (_browserAction == null) _throwNotAvailable();

   var completer = new ChromeCompleter<Map<String, dynamic>>.oneArg(mapify);
   _browserAction.callMethod('openPopup', [completer.callback]);
   return completer.future;
 }

 /**
  * Fired when a browser action icon is clicked.  This event will not fire if
  * the browser action has a popup.
  */
 Stream<Tab> get onClicked => _onClicked.stream;

 final ChromeStreamController<Tab> _onClicked =
     new ChromeStreamController<Tab>.oneArg(_browserAction, 'onClicked', _createTab);

 void _throwNotAvailable() {
   throw new UnsupportedError("'chrome.browserAction' is not available");
 }
}

Extends

ChromeApi > ChromeBrowserAction

Properties

final bool available #

Returns true if the API is available. The common causes of an API not being avilable are:

  • a permission is missing in the application's manifest.json file
  • the API is defined on a newer version of Chrome then the current runtime
docs inherited from ChromeApi
bool get available => _browserAction != null;

final Stream<Tab> onClicked #

Fired when a browser action icon is clicked. This event will not fire if the browser action has a popup.

Stream<Tab> get onClicked => _onClicked.stream;

Methods

void disable([int tabId]) #

Disables the browser action for a tab.

tabId The id of the tab for which you want to modify the browser action.

void disable([int tabId]) {
 if (_browserAction == null) _throwNotAvailable();

 _browserAction.callMethod('disable', [tabId]);
}

void enable([int tabId]) #

Enables the browser action for a tab. By default, browser actions are enabled.

tabId The id of the tab for which you want to modify the browser action.

void enable([int tabId]) {
 if (_browserAction == null) _throwNotAvailable();

 _browserAction.callMethod('enable', [tabId]);
}

Future<ColorArray> getBadgeBackgroundColor(BrowserActionGetBadgeBackgroundColorParams details) #

Gets the background color of the browser action.

Future<ColorArray> getBadgeBackgroundColor(BrowserActionGetBadgeBackgroundColorParams details) {
 if (_browserAction == null) _throwNotAvailable();

 var completer = new ChromeCompleter<ColorArray>.oneArg(_createColorArray);
 _browserAction.callMethod('getBadgeBackgroundColor', [jsify(details), completer.callback]);
 return completer.future;
}

Future<String> getBadgeText(BrowserActionGetBadgeTextParams details) #

Gets the badge text of the browser action. If no tab is specified, the non-tab-specific badge text is returned.

Future<String> getBadgeText(BrowserActionGetBadgeTextParams details) {
 if (_browserAction == null) _throwNotAvailable();

 var completer = new ChromeCompleter<String>.oneArg();
 _browserAction.callMethod('getBadgeText', [jsify(details), completer.callback]);
 return completer.future;
}

Future<String> getPopup(BrowserActionGetPopupParams details) #

Gets the html document set as the popup for this browser action.

Future<String> getPopup(BrowserActionGetPopupParams details) {
 if (_browserAction == null) _throwNotAvailable();

 var completer = new ChromeCompleter<String>.oneArg();
 _browserAction.callMethod('getPopup', [jsify(details), completer.callback]);
 return completer.future;
}

Future<String> getTitle(BrowserActionGetTitleParams details) #

Gets the title of the browser action.

Future<String> getTitle(BrowserActionGetTitleParams details) {
 if (_browserAction == null) _throwNotAvailable();

 var completer = new ChromeCompleter<String>.oneArg();
 _browserAction.callMethod('getTitle', [jsify(details), completer.callback]);
 return completer.future;
}

Future<Map<String, dynamic>> openPopup() #

Opens the extension popup window in the active window but does not grant tab permissions.

Returns: JavaScript 'window' object for the popup window if it was succesfully opened.

Future<Map<String, dynamic>> openPopup() {
 if (_browserAction == null) _throwNotAvailable();

 var completer = new ChromeCompleter<Map<String, dynamic>>.oneArg(mapify);
 _browserAction.callMethod('openPopup', [completer.callback]);
 return completer.future;
}

void setBadgeBackgroundColor(BrowserActionSetBadgeBackgroundColorParams details) #

Sets the background color for the badge.

void setBadgeBackgroundColor(BrowserActionSetBadgeBackgroundColorParams details) {
 if (_browserAction == null) _throwNotAvailable();

 _browserAction.callMethod('setBadgeBackgroundColor', [jsify(details)]);
}

void setBadgeText(BrowserActionSetBadgeTextParams details) #

Sets the badge text for the browser action. The badge is displayed on top of the icon.

void setBadgeText(BrowserActionSetBadgeTextParams details) {
 if (_browserAction == null) _throwNotAvailable();

 _browserAction.callMethod('setBadgeText', [jsify(details)]);
}

Future setIcon(BrowserActionSetIconParams details) #

Sets the icon for the browser action. The icon can be specified either as the path to an image file or as the pixel data from a canvas element, or as dictionary of either one of those. Either the <b>path</b> or the <b>imageData</b> property must be specified.

Future setIcon(BrowserActionSetIconParams details) {
 if (_browserAction == null) _throwNotAvailable();

 var completer = new ChromeCompleter.noArgs();
 _browserAction.callMethod('setIcon', [jsify(details), completer.callback]);
 return completer.future;
}

void setPopup(BrowserActionSetPopupParams details) #

Sets the html document to be opened as a popup when the user clicks on the browser action's icon.

void setPopup(BrowserActionSetPopupParams details) {
 if (_browserAction == null) _throwNotAvailable();

 _browserAction.callMethod('setPopup', [jsify(details)]);
}

void setTitle(BrowserActionSetTitleParams details) #

Sets the title of the browser action. This shows up in the tooltip.

void setTitle(BrowserActionSetTitleParams details) {
 if (_browserAction == null) _throwNotAvailable();

 _browserAction.callMethod('setTitle', [jsify(details)]);
}