Page actions are a simple way to represent actions that can be taken on a page ("Email this page", "Share with Facebook", etc).
Page actions are displayed as icons on the right side of the OmniBox. The RSS icon in the following screenshot represents a page action that lets you subscribe to the RSS feed for the current page.
Manifest
Developers can declare page actions in the manifest using the following syntax:
"page_actions": [ { "id": "myaction", // Chosen by the developer. Should be unique within their extension. "name": "Do action", // The page action name, also used as tooltip (unless overridden). "icons": ["favicon.png", "favicon2.png"] } ]
Supported icon image formats include for example: png, bmp, ico, jpg, gif. If an image larger than 16x16 is specified, it will be resized to fit. For optimal performance, consider using an image that does not have to be resized to fit.
Events
Each page action displays an icon in the OmniBox. Whenever the user clicks the icon an event is sent to the extension, signifying that the user wants to apply an action to the current page. To receive notifications about the event, the extension must register a listener.
Page action events are created dynamically using the id of the page action declared in the manifest. For example, a page action with id 'foo' will setup an event called chrome.pageActions["foo"]. An extension would then register listeners like so:
chrome.pageActions["foo"].addListener(function(object reply) { console.log(reply.pageActionId); // Display the id of the page action. console.log(reply.data.tabId); // Display the id of the tab for which the page action event applies. console.log(reply.data.tabUrl); // Display the URL of the page for which the page action event applies. });
Parameters
reply ( object )
An object containing the information about the event. Contains the following properties:
pageActionId ( string )
The id of the page action that triggered the event.
data ( object )
An object specifying what tab and which page the event applies to. Contains the following properties:
tabId ( string )
The id of the tab that was active when the event was triggered.
tabUrl ( string )
The url of the page for which the page action applies to.
API reference: chrome.pageActions
Methods
enableForTab
Enables a page action for a particular tab+url combination (makes its icon visible in the OmniBox when a certain url is active in a given tab). The page action will automatically be disabled (its icon hidden) if the user navigates to a new URL or closes the tab. The action will also automatically be enabled/disabled as the user switches tabs.
Parameters
- pageActionId ( string )
- An extension can have multiple page actions specified in the manifest, each with a unique identifier. This string identifies which page action you want to enable (and must match a page action id declared in the manifest).
- action ( object )
- An object specifing what action should be applied to the page action. Contains the following properties:
-
- tabId ( integer )
- The id of the tab for which you want to enable the page action.
- url ( string )
- The URL of the page you want the page action to apply to. If the URL specified does not match the currently navigated URL (user has navigated to another page) then no action is taken.
- title ( optional string )
- Specifying |title| allows you to change the tooltip that appears when you hover over the page action icon in the OmniBox. This parameter is optional and if omitted then the page action |name| property declared in the manifest is used.
- iconId ( optional integer )
- A zero-based index into the |icons| vector specified in the manifest. This parameter is optional and if omitted then the first icon in the |icons| vector of the page action is used. This id is useful to represent different page action states. Example: An RSS feed icon could have a 'subscribe now' icon and an 'already subscribed' icon.
- tabId
Returns
disableForTab
Disables a page action for a particular tab+url combination (makes its OmniBox page action icon hidden when a certain url is active in a given tab). This can be useful to disable a page action before the user navigates away from a page containing an enabled page action.
Parameters
- pageActionId ( string )
- An extension can have multiple page actions specified in the manifest, each with a unique identifier. This string identifies which page action you want to disable (and must match a page action id declared in the manifest).
- action ( object )
- An object specifying what action should be applied to the page action. Contains the following properties:
-
- tabId ( integer )
- The id of the tab for which you want to disable the page action.
- url ( string )
- The URL of the page you want the page action to not apply to. If the URL specified does not match the currently navigated URL (user has navigated to another page) then no action is taken.
- tabId