tabs API

The tabs API supports creating, modifying and interacting with tabs in Thunderbird windows.

Permissions

activeTab

tabs

Access browser tabs

tabHide

Hide and show browser tabs

Functions

get(tabId)

Retrieves details about the specified tab.

Parameters

tabId

(integer)

Return type (Promise)

Tab

getCurrent()

Gets the tab that this script call is being made from. May be undefined if called from a non-tab context (for example: a background page or popup view).

Return type (Promise)

Tab

connect(tabId, [connectInfo])

– [Added in TB 82, backported to TB 78.4.0]

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

tabId

(integer)

[connectInfo]

(object, optional)

[frameId]

(integer, optional)

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

[name]

(string, optional)

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

Return type (Promise)

A port that can be used to communicate with the content scripts running in the specified tab.

sendMessage(tabId, message, [options])

– [Added in TB 82, backported to TB 78.4.0]

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

tabId

(integer)

message

(any)

[options]

(object, optional)

[frameId]

(integer, optional)

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

Return type (Promise)

any

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.

create(createProperties)

Creates a new tab or switches to a tab with the given URL, if it exists already.

Parameters

createProperties

(object)

Properties for the new tab. Defaults to an empty tab, if no url is provided.

[active]

(boolean, optional)

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

[index]

(integer, optional)

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.

[selected]

(boolean, optional) Unsupported.

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

[url]

(string, optional)

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.

[windowId]

(integer, optional)

The window to create the new tab in. Defaults to the current window.

Return type (Promise)

Tab

Details about the created tab. Will contain the ID of the new tab.

duplicate(tabId)

Duplicates a tab.

Parameters

tabId

(integer)

The ID of the tab which is to be duplicated.

Return type (Promise)

Tab

Details about the duplicated tab. The Tab object doesn’t contain url, title and favIconUrl if the tabs permission has not been requested.

query(queryInfo)

Gets all tabs that have the specified properties, or all tabs if no properties are specified.

Parameters

queryInfo

(object)

[active]

(boolean, optional)

Whether the tabs are active in their windows.

[currentWindow]

(boolean, optional)

Whether the tabs are in the current window.

[highlighted]

(boolean, optional)

Whether the tabs are highlighted. Works as an alias of active.

[index]

(integer, optional)

The position of the tabs within their windows.

[lastFocusedWindow]

(boolean, optional)

Whether the tabs are in the last focused window.

[mailTab]

(boolean, optional)

Whether the tab is a Thunderbird 3-pane tab.

[status]

(TabStatus, optional)

Whether the tabs have completed loading.

[title]

(string, optional)

Match page titles against a pattern.

[type]

(string, optional)

– [Added in TB 91]

Match tabs against the given Tab.type (see Tab). Ignored if queryInfo.mailTab is specified.

[url]

(string or array of string, optional)

Match tabs against one or more URL Patterns. Note that fragment identifiers are not matched.

[windowId]

(integer, optional)

The ID of the parent window, or WINDOW_ID_CURRENT for the current window.

[windowType]

(WindowType, optional)

The type of window the tabs are in.

Return type (Promise)

array of Tab

update([tabId], updateProperties)

Modifies the properties of a tab. Properties that are not specified in updateProperties are not modified.

Parameters

[tabId]

(integer, optional)

Defaults to the selected tab of the current window.

updateProperties

(object)

Properties which should to be updated.

[active]

(boolean, optional)

Set this to true, if the tab should be active. Does not affect whether the window is focused (see update(windowId, updateInfo)). Setting this to false has no effect.

[url]

(string, optional)

A URL to navigate the tab to. Only applicable for content tabs and active mail tabs.

Return type (Promise)

Tab

Details about the updated tab. The Tab object doesn’t contain url, title and favIconUrl if the tabs permission has not been requested.

move(tabIds, moveProperties)

Moves one or more tabs to a new position within its window, or to a new window. Note that tabs can only be moved to and from windows of type normal.

Parameters

tabIds

(integer or array of integer)

The tab or list of tabs to move.

moveProperties

(object)

index

(integer)

The position to move the window to. -1 will place the tab at the end of the window.

[windowId]

(integer, optional)

Defaults to the window the tab is currently in.

Return type (Promise)

Tab or array of Tab

Details about the moved tabs.

reload([tabId], [reloadProperties])

Reload a tab.

Parameters

[tabId]

(integer, optional)

The ID of the tab to reload; defaults to the selected tab of the current window.

[reloadProperties]

(object, optional)

[bypassCache]

(boolean, optional)

Whether using any local cache. Default is false.

remove(tabIds)

Closes one or more tabs.

Parameters

tabIds

(integer or array of integer)

The tab or list of tabs to close.

executeScript([tabId], details)

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

Changes in Thunderbird 77

With the compose permission, this now works in the document of email messages during composition.

Parameters

[tabId]

(integer, optional)

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

details

Details of the script to run.

Return type (Promise)

array of any

The result of the script in every injected frame.

insertCSS([tabId], details)

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

Changes in Thunderbird 77

With the compose permission, this now works in the document of email messages during composition.

Parameters

[tabId]

(integer, optional)

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

details

Details of the CSS text to insert.

removeCSS([tabId], details)

Removes injected CSS from a page. For details, see the programmatic injection section of the content scripts doc.

Changes in Thunderbird 77

With the compose permission, this now works in the document of email messages during composition.

Parameters

[tabId]

(integer, optional)

The ID of the tab from which to remove the injected CSS; defaults to the active tab of the current window.

details

Details of the CSS text to remove.

Events

onCreated

Fired when a tab is created. Note that the tab’s URL may not be set at the time this event fired, but you can listen to onUpdated events to be notified when a URL is set.

Parameters for onCreated.addListener(listener)

listener(tab)

A function that will be called when this event occurs.

Parameters passed to the listener function

tab

(Tab)

Details of the tab that was created.

onUpdated

Fired when a tab is updated.

Parameters for onUpdated.addListener(listener, filter)

listener(tabId, changeInfo, tab)

A function that will be called when this event occurs.

[filter]

(UpdateFilter, optional)

A set of filters that restricts the events that will be sent to this listener.

Parameters passed to the listener function

tabId

(integer)

changeInfo

(object)

Lists the changes to the state of the tab that was updated.

[favIconUrl]

(string, optional)

The tab’s new favicon URL.

[status]

(string, optional)

The status of the tab. Can be either loading or complete.

[url]

(string, optional)

The tab’s URL if it has changed.

tab

(Tab)

Gives the state of the tab that was updated.

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 onDetached.

Parameters for onMoved.addListener(listener)

listener(tabId, moveInfo)

A function that will be called when this event occurs.

Parameters passed to the listener function

tabId

(integer)

moveInfo

(object)

fromIndex

(integer)

toIndex

(integer)

windowId

(integer)

onActivated

Fires when the active tab in a window changes. Note that the tab’s URL may not be set at the time this event fired, but you can listen to onUpdated events to be notified when a URL is set.

Parameters for onActivated.addListener(listener)

listener(activeInfo)

A function that will be called when this event occurs.

Parameters passed to the listener function

activeInfo

(object)

tabId

(integer)

The ID of the tab that has become active.

windowId

(integer)

The ID of the window the active tab changed inside of.

onDetached

Fired when a tab is detached from a window, for example because it is being moved between windows.

Parameters for onDetached.addListener(listener)

listener(tabId, detachInfo)

A function that will be called when this event occurs.

Parameters passed to the listener function

tabId

(integer)

detachInfo

(object)

oldPosition

(integer)

oldWindowId

(integer)

onAttached

Fired when a tab is attached to a window, for example because it was moved between windows.

Parameters for onAttached.addListener(listener)

listener(tabId, attachInfo)

A function that will be called when this event occurs.

Parameters passed to the listener function

tabId

(integer)

attachInfo

(object)

newPosition

(integer)

newWindowId

(integer)

onRemoved

Fired when a tab is closed.

Parameters for onRemoved.addListener(listener)

listener(tabId, removeInfo)

A function that will be called when this event occurs.

Parameters passed to the listener function

tabId

(integer)

removeInfo

(object)

isWindowClosing

(boolean)

Is true when the tab is being closed because its window is being closed.

windowId

(integer)

The window whose tab is closed.

Types

Tab

object

active

(boolean)

Whether the tab is active in its window. (Does not necessarily mean the window is focused.)

highlighted

(boolean)

Whether the tab is highlighted. Works as an alias of active

index

(integer)

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

selected

(boolean) Unsupported.

Whether the tab is selected.

[favIconUrl]

(string, optional)

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.

[height]

(integer, optional)

The height of the tab in pixels.

[id]

(integer, optional)

The ID of the tab. Tab IDs are unique within a session. Under some circumstances a Tab may not be assigned an ID. Tab ID can also be set to TAB_ID_NONE for apps and devtools windows.

[mailTab]

(boolean, optional)

Whether the tab is a 3-pane tab.

[status]

(string, optional)

Either loading or complete.

[title]

(string, optional)

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

[type]

(string, optional)

– [Added in TB 91]

Supported values:

addressBook

calendar

calendarEvent

calendarTask

chat

content

mail

messageCompose

messageDisplay

special

tasks

[url]

(string, optional)

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

[width]

(integer, optional)

The width of the tab in pixels.

[windowId]

(integer, optional)

The ID of the window the tab is contained within.

TabStatus

Whether the tabs have completed loading.

string

Supported values:

loading

complete

UpdateFilter

An object describing filters to apply to tabs.onUpdated events.

object

[properties]

(array of UpdatePropertyName, optional)

A list of property names. Events that do not match any of the names will be filtered out.

[tabId]

(integer, optional)

[urls]

(array of string, optional)

A list of URLs or URL patterns. Events that cannot match any of the URLs will be filtered out. Filtering with urls requires the tabs or activeTab permission.

[windowId]

(integer, optional)

UpdatePropertyName

Event names supported in onUpdated.

string

Supported values:

favIconUrl

status

title

WindowType

The type of a window. Under some circumstances a Window may not be assigned a type property.

string

Supported values:

normal

popup

panel

app

devtools

addressBook

messageCompose

messageDisplay

Properties

TAB_ID_NONE

An ID which represents the absence of a tab.