Contents
Use page actions to put icons inside the address bar. Page actions represent actions that can be taken on the current page, but that aren't applicable to all pages. Some examples:
- Subscribe to this page's RSS feed
- Make a slideshow out of this page's photos
The RSS icon in the following screenshot represents a page action that lets you subscribe to the RSS feed for the current page.
If you want the extension's icon to always be visible, use a browser action instead.
Manifest
Register your page action in the extension manifest like this:
"page_action": { "default_title": "Do action", // optional; shown in tooltip "default_icon": "icons/foo.png", // optional "popup": "popup.html" // optional }
Note: Even if you don't include any of the values, you must include an empty page_action entry in your manifest so that the system reserves a slot for your page action in the address bar.
Set "default_icon" if at all possible. Users see the default icon when they install your extension, which helps them know what to look for when your page action is active for a given page.
Parts of the UI
Like browser actions, page actions have an icon and can also have a tooltip and popup; they can't have badges, however. In addition, page actions can appear and disappear. You can find information about icons, tooltips, and popups by reading about the browser action UI.
You make a page action appear and disappear using the show() and hide() methods, respectively. By default, a page action is hidden. When you show it, you specify the tab in which the icon should appear. The icon remains visible until the tab is closed or starts displaying a different URL (because the user clicks a link, for example).
Tips
For the best visual impact, follow these guidelines:
- Do use page actions for features that make sense for only a few pages.
- Don't use page actions for features that make sense for most pages. Use browser actions instead.
- Do use icons that are slightly lighter weight than browser action icons. Most icons that Chrome displays in the location bar are smaller than 19 pixels. If the edge pixels are used, they are usually only used for a faint shadow.
- Don't constantly animate your icon. That's just annoying.
API reference: chrome.pageAction
Methods
hide
Hides the page action.
Parameters
-
tabId
( integer )
- The id of the tab for which you want to modify the page action.
Returns
setIcon
Sets the icon for the page action. The icon can be specified either as the path to an image file or as the pixel data from a canvas element. Either the path or the imageData property must be specified.
Parameters
-
details
( object )
- Undocumented.
-
-
tabId
( integer )
- The id of the tab for which you want to modify the page action.
-
imageData
( optional any )
- Pixel data for an image. Must be an ImageData object (for example, from a canvas element).
-
path
( optional string )
- Relative path to an image in the extension to show in the browser action.
-
iconIndex
( optional integer )
- Deprecated. The zero-based index into the icons vector specified in the manifest.
-
tabId
Returns
setTitle
Sets the title of the page action. This is displayed in a tooltip over the page action.
Parameters
-
details
( object )
- Undocumented.
-
-
tabId
( integer )
- The id of the tab for which you want to modify the page action.
-
title
( string )
- The tooltip string.
-
tabId