chrome.tabs

Use the chrome.tabs API to interact with the browser's tab system. You can use this API to create, modify, and rearrange tabs in the browser.

Availability:

Since Chrome 17.

Permissions:

The majority of the chrome.tabs API can be used without declaring
any permission.
However, the
"tabs" permission is required in order to populate the
url,
title, and
favIconUrl properties of
Tab.

Manifest

You can use most chrome.tabs methods and events without declaring
any permissions in the extension's manifest file.
However, if you require access to the
url,
title, or
favIconUrl properties of
tabs.Tab,
you must declare the "tabs" permission in the manifest,
as shown below:

{
"name": "My extension",
...
"permissions": [
"tabs"
],
...
}

Examples

You can find simple examples of manipulating tabs with the
chrome.tabs API in the
examples/api/tabs
directory.
For other examples and for help in viewing the source code, see
Samples.

The reason the tab was muted or unmuted. Not set if the tab's mute state has never been changed.

string

(optional)
extensionId

The ID of the extension that changed the muted state. Not set if an extension was not the reason the muted state last changed.

Tab

properties

integer

(optional)
id

The ID of the tab. Tab IDs are unique within a browser session. Under some circumstances a Tab may not be assigned an ID, for example when querying foreign tabs using the sessions API, in which case a session ID may be present. Tab ID can also be set to chrome.tabs.TAB_ID_NONE for apps and devtools windows.

integer

index

The zero-based index of the tab within its window.

integer

windowId

The ID of the window the tab is contained within.

integer

(optional)
openerTabId

Since Chrome 18.

The ID of the tab that opened this tab, if any. This property is only present if the opener tab still exists.

The URL the tab is displaying. This property is only present if the extension's manifest includes the "tabs" permission.

string

(optional)
title

The title of the tab. This property is only present if the extension's manifest includes the "tabs" permission.

string

(optional)
favIconUrl

The URL of the tab's favicon. This property is only present if the extension's manifest includes the "tabs" permission. It may also be an empty string if the tab is loading.

string

(optional)
status

Either loading or complete.

boolean

incognito

Whether the tab is in an incognito window.

integer

(optional)
width

Since Chrome 31.

The width of the tab in pixels.

integer

(optional)
height

Since Chrome 31.

The height of the tab in pixels.

string

(optional)
sessionId

Since Chrome 31.

The session ID used to uniquely identify a Tab obtained from the sessions API.

ZoomSettingsMode

Enum

"automatic"

Zoom changes are handled automatically by the browser.

"manual"

Overrides the automatic handling of zoom changes. The onZoomChange event will still be dispatched, and it is the responsibility of the extension to listen for this event and manually scale the page. This mode does not support per-origin zooming, and will thus ignore the scope zoom setting and assume per-tab.

"disabled"

Disables all zooming in the tab. The tab will revert to the default zoom level, and all attempted zoom changes will be ignored.

Defines how zoom changes are handled, i.e. which entity is responsible for the actual scaling of the page; defaults to automatic.

ZoomSettingsScope

Enum

"per-origin"

Zoom changes will persist in the zoomed page's origin, i.e. all other tabs navigated to that same origin will be zoomed as well. Moreover, per-origin zoom changes are saved with the origin, meaning that when navigating to other pages in the same origin, they will all be zoomed to the same zoom factor. The per-origin scope is only available in the automatic mode.

"per-tab"

Zoom changes only take effect in this tab, and zoom changes in other tabs will not affect the zooming of this tab. Also, per-tab zoom changes are reset on navigation; navigating a tab will always load pages with their per-origin zoom factors.

Defines whether zoom changes will persist for the page's origin, or only take effect in this tab; defaults to per-origin when in automatic mode, and per-tab otherwise.

connect

Connects to the content script(s) in the specified tab. The runtime.onConnect event is fired in each content script running in the specified tab for the current extension. For more details, see Content Script Messaging.

Parameters

integer

tabId

object

(optional)
connectInfo

string

(optional)
name

Will be passed into onConnect for content scripts that are listening for the connection event.

integer

(optional)
frameId

Since Chrome 41.

Open a port to a specific frame identified by frameId instead of all frames in the tab.

sendRequest

Sends a single request to the content script(s) in the specified tab, with an optional callback to run when a response is sent back. The extension.onRequest event is fired in each content script running in the specified tab for the current extension.

Parameters

integer

tabId

any

request

function

(optional)
responseCallback

If you specify the responseCallback parameter, it should
be a function that looks like this:

function(any response) {...};

any

response

The JSON response object sent by the handler of the request. If an error occurs while connecting to the specified tab, the callback will be called with no arguments and runtime.lastError will be set to the error message.

sendMessage

Sends a single message to the content script(s) in the specified tab, with an optional callback to run when a response is sent back. The runtime.onMessage event is fired in each content script running in the specified tab for the current extension.

Parameters

integer

tabId

any

message

The message to send. This message should be a JSON-ifiable object.

object

(optional)
options

Since Chrome 41.

integer

(optional)
frameId

Send a message to a specific frame identified by frameId instead of all frames in the tab.

function

(optional)
responseCallback

If you specify the responseCallback parameter, it should
be a function that looks like this:

function(any response) {...};

any

response

The JSON response object sent by the handler of the message. If an error occurs while connecting to the specified tab, the callback will be called with no arguments and runtime.lastError will be set to the error message.

The position the tab should take in the window. The provided value will be clamped to between zero and the number of tabs in the window.

string

(optional)
url

The URL to navigate the tab to initially. Fully-qualified URLs must include a scheme (i.e. 'http://www.google.com', not 'www.google.com'). Relative URLs will be relative to the current page within the extension. Defaults to the New Tab Page.

boolean

(optional)
active

Whether the tab should become the active tab in the window. Does not affect whether the window is focused (see windows.update). Defaults to true.

boolean

(optional)
selected

Deprecated since Chrome 33.
Please use active.

Whether the tab should become the selected tab in the window. Defaults to true

boolean

(optional)
pinned

Whether the tab should be pinned. Defaults to false

integer

(optional)
openerTabId

Since Chrome 18.

The ID of the tab that opened this tab. If specified, the opener tab must be in the same window as the newly created tab.

function

(optional)
callback

If you specify the callback parameter, it should
be a function that looks like this:

An ISO language code such as en or fr. For a complete list of languages supported by this method, see kLanguageInfoTable. The 2nd to 4th columns will be checked and the first non-NULL value will be returned except for Simplified Chinese for which zh-CN will be returned. For an unknown language, und will be returned.

When format is "jpeg", controls the quality of the resulting image. This value is ignored for PNG images. As quality is decreased, the resulting image will have more visual artifacts, and the number of bytes needed to store it will decrease.

function

callback

The callback parameter should be a function
that looks like this:

function(string dataUrl) {...};

string

dataUrl

A data URL which encodes an image of the visible area of the captured tab. May be assigned to the 'src' property of an HTML Image element for display.

executeScript

Injects JavaScript code into a page. For details, see the programmatic injection section of the content scripts doc.

Parameters

integer

(optional)
tabId

The ID of the tab in which to run the script; defaults to the active tab of the current window.

object

details

Details of the script to run. Either the code or the file property must be set, but both may not be set at the same time.

string

(optional)
code

JavaScript or CSS code to inject.

Warning:Be careful using the code parameter. Incorrect use of it may open your extension to cross site scripting attacks.

string

(optional)
file

JavaScript or CSS file to inject.

boolean

(optional)
allFrames

If allFrames is true, implies that the JavaScript or CSS should be injected into all frames of current page. By default, it's false and is only injected into the top frame. If true and frameId is set, then the code is inserted in the selected frame and all of its child frames.

integer

(optional)
frameId

Since Chrome 39.

The frame where the script or CSS should be injected. Defaults to 0 (the top-level frame).

boolean

(optional)
matchAboutBlank

Since Chrome 39.

If matchAboutBlank is true, then the code is also injected in about:blank and about:srcdoc frames if your extension has access to its parent document. Code cannot be inserted in top-level about:-frames. By default it is false.

enum of "document_start", "document_end", or "document_idle"

(optional)
runAt

Since Chrome 20.

The soonest that the JavaScript or CSS will be injected into the tab. Defaults to "document_idle".

function

(optional)
callback

Called after all the JavaScript has been executed.

If you specify the callback parameter, it should
be a function that looks like this:

The ID of the tab in which to insert the CSS; defaults to the active tab of the current window.

object

details

Details of the CSS text to insert. Either the code or the file property must be set, but both may not be set at the same time.

string

(optional)
code

JavaScript or CSS code to inject.

Warning:Be careful using the code parameter. Incorrect use of it may open your extension to cross site scripting attacks.

string

(optional)
file

JavaScript or CSS file to inject.

boolean

(optional)
allFrames

If allFrames is true, implies that the JavaScript or CSS should be injected into all frames of current page. By default, it's false and is only injected into the top frame. If true and frameId is set, then the code is inserted in the selected frame and all of its child frames.

integer

(optional)
frameId

Since Chrome 39.

The frame where the script or CSS should be injected. Defaults to 0 (the top-level frame).

boolean

(optional)
matchAboutBlank

Since Chrome 39.

If matchAboutBlank is true, then the code is also injected in about:blank and about:srcdoc frames if your extension has access to its parent document. Code cannot be inserted in top-level about:-frames. By default it is false.

enum of "document_start", "document_end", or "document_idle"

(optional)
runAt

Since Chrome 20.

The soonest that the JavaScript or CSS will be injected into the tab. Defaults to "document_idle".

function

(optional)
callback

Called when all the CSS has been inserted.

If you specify the callback parameter, it should
be a function that looks like this:

discard

Discards a tab from memory. Discarded tabs are still visible on the tab strip and are reloaded when activated.

Parameters

integer

(optional)
tabId

The ID of the tab to be discarded. If specified, the tab will be discarded unless it's active or already discarded. If omitted, the browser will discard the least important tab. This can fail if no discardable tabs exist.

function

(optional)
callback

Called after the operation is completed.

If you specify the callback parameter, it should
be a function that looks like this:

onMoved

Fired when a tab is moved within a window. Only one move event is fired, representing the tab the user directly moved. Move events are not fired for the other tabs that must move in response. This event is not fired when a tab is moved between windows. For that, see tabs.onDetached.