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)

[frameId]

(integer)

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

[name]

(string)

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)

[frameId]

(integer)

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 content tab. Use the messageDisplay API to open messages. Only supported in normal windows.

Parameters

createProperties

(object)

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

[active]

(boolean)

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)

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) Unsupported.

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

[url]

(string)

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)

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)

Whether the tabs are active in their windows.

[currentWindow]

(boolean)

Whether the tabs are in the current window.

[highlighted]

(boolean)

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

[index]

(integer)

The position of the tabs within their windows.

[lastFocusedWindow]

(boolean)

Whether the tabs are in the last focused window.

[mailTab]

(boolean)

Whether the tab is a Thunderbird 3-pane tab.

[status]

Whether the tabs have completed loading.

[title]

(string)

Match page titles against a pattern.

[type]

(string)

– [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)

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

[windowId]

(integer)

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

[windowType]

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)

Defaults to the selected tab of the current window.

updateProperties

(object)

Properties which should to be updated.

[active]

(boolean)

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)

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)

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)

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

[reloadProperties]

(object)

[bypassCache]

(boolean)

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)

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)

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)

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]

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)

The tab’s new favicon URL.

[status]

(string)

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

[url]

(string)

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)

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)

The height of the tab in pixels.

[id]

(integer)

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)

Whether the tab is a 3-pane tab.

[status]

(string)

Either loading or complete.

[title]

(string)

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

[type]

(string)

– [Added in TB 91]

Supported values:

addressBook

calendar

calendarEvent

calendarTask

chat

content

mail

messageCompose

messageDisplay

special

tasks

[url]

(string)

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

[width]

(integer)

The width of the tab in pixels.

[windowId]

(integer)

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)

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

[tabId]

(integer)

[urls]

(array of string)

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)

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

messageCompose

messageDisplay

Properties

TAB_ID_NONE

An ID which represents the absence of a tab.