Changing the page action and browser action popup page

3,492 views
Skip to first unread message

Sam Kerner

unread,
Mar 30, 2010, 4:15:33 PM3/30/10
to Chromium-extensions
Chrome Extension Developers,

Page and browser actions can have a popup, set in the manifest, that opens when the user clicks the extension's icon:
{
 ...
 "browser_action": {
   ...
   "popup": "popup.html"        // optional
 },
 ...
}


The dev channel includes two new methods that allow you to dynamically change this popup:

  chrome.pageAction.setPopup(object details)
  chrome.browserAction.setPopup(object details)



Here is a small example:

chrome.tabs.getSelected(null, function(tab) {
  // When the browser action is clicked, set the popup for |tab|.
  chrome.browserAction.onClicked.addListener(function(tab) {
    chrome.browserAction.setPopup({
      tabId: tab.id,          // Set the new popup for this tab.
      popup: 'a_popup.html'   // Open this html file within the popup.
    });
  });
});

Setting the popup to the empty string ('') disables the popup.  Event chrome.(page|browser)Action.onClicked will fire when the user clicks on the action's icon, if no popup is set.  

This enhancement should be in the stable channel in version 5.0. Like all new API additions, it will not work on older versions of chrome.  You can prevent users of older chrome versions from installing your extension using the "minimum_chrome_version" property in your manifest:

{
  ...
  "minimum_chrome_version": "5.0"
}


As always, let us know of any issues you find.


Sam


Weiller Santos

unread,
Dec 8, 2014, 11:36:23 AM12/8/14
to chromium-...@chromium.org
skerner how should I do the popup.html ?
Reply all
Reply to author
Forward
0 new messages