tabs API

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

Permissions

The following permissions influence the behavior of the API. Depending on which permissions are requested, additional methods might be available, or certain data may be included in responses.

Hint

Request permissions only when needed. Unnecessary requests may result in rejection during ATN review.

activeTab

activeTab

Grant host permission to the currently active tab, allowing to read title, url and favIconUrl properties, or to inject content scripts.

contextualIdentities

contextualIdentities

Grant access to some or all methods of the contextualIdentities API.

cookies

cookies

Grant access to some or all methods of the cookies API.

tabs

tabs

Grant host permission to all active and inactive tabs, allowing to read title, url and favIconUrl properties, or to inject content scripts.

Functions

connect(tabId, [connectInfo])

– [Added in TB 82]

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

tabId

(integer)

connectInfo

[connectInfo]

(object, optional)

frameId

[frameId]

(integer, optional)

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

name

[name]

(string, optional)

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

Return type (Promise)

_returns

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

create(createProperties)

– [Added in TB 62]

Creates a new content tab. To create message tabs, use the open(openProperties). Only supported in normal windows. Same-site links in the loaded page are opened within Thunderbird, all other links are opened in the user’s default browser. To override this behavior, add-ons have to register a content script , capture click events and handle them manually.

Parameters

createProperties

createProperties

(object)

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

active

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

cookieStoreId

[cookieStoreId]

(string, optional)

– [Added in TB 115]

The CookieStore id the new tab should use. Either a custom id created using the contextualIdentities API, or a built-in one: firefox-default, firefox-container-1, firefox-container-2, firefox-container-3, firefox-container-4, firefox-container-5.

Note

The naming pattern of the built-in cookie stores was deliberately not changed for Thunderbird, but kept for compatibility reasons.

Note

The cookies permission is required to be able to specify this property. Furthermore, the contextualIdentities permission should be requested, to enable the contextual identities feature (enabled by default only on Thunderbird Daily).

index

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

linkHandler

[linkHandler]

(string, optional)

– [Added in TB 136]

Thunderbird is a mail client, not a browser. It is possible to load a web page, but opening follow-up pages through hyperlinks should be handled by the user’s default browser. This property specifies to what extent this behavior should be enforced. The default balanced link handler will open links to the same host directly in Thunderbird, everything else will be opened in the user’s default browser. A relaxed link handler will open all links inside of Thunderbird, a strict link handler will open all links in the user’s default browser, except links to the same page.

Supported values:

balanced

balanced

relaxed

relaxed

strict

strict

selected

[selected]

(boolean, optional) Unsupported.

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

url

[url]

(string, optional)

The URL to navigate the tab to initially. If the URL points to a content page (a web page, an extension page or a registered WebExtension protocol handler page), the tab will navigate to the requested page. All other URLs will be opened externally after creating an empty tab. Fully-qualified URLs must include a scheme (i.e. http://www.google.com, not www.google.com). Relative URLs will be relative to the root of the extension.

windowId

[windowId]

(integer, optional)

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

Return type (Promise)

_returns

A Promise that will be fulfilled with a Tab object containing details about the created tab. If the tab could not be created (for example, because it was added to a non-normal window) the promise will be rejected with an error message. The returned promise resolves as soon as the tab has been created. The tab may still be loading, with its title being loading… and its URL being about:blank. To detect when the tab has finished loading, listen to the onUpdated event before creating the tab.

duplicate(tabId)

– [Added in TB 62]

Duplicates a tab.

Parameters

tabId

tabId

(integer)

The ID of the tab which is to be duplicated.

Return type (Promise)

_returns

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

executeScript([tabId], details)

– [Added in TB 62]

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

Parameters

tabId

[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

Details of the script to run.

Return type (Promise)

_returns

array of any

The result of the script in every injected frame.

get(tabId)

– [Added in TB 62]

Retrieves details about the specified tab.

Parameters

tabId

tabId

(integer)

Return type (Promise)

_returns

getCurrent()

– [Added in TB 62]

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

Return type (Promise)

_returns

insertCSS([tabId], details)

– [Added in TB 62]

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

Parameters

tabId

[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

Details of the CSS text to insert.

move(tabIds, moveProperties)

– [Added in TB 62]

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

Parameters

tabIds

tabIds

(integer or array of integer)

The tab or list of tabs to move.

moveProperties

moveProperties

(object)

index

index

(integer)

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

windowId

[windowId]

(integer, optional)

Defaults to the window the tab is currently in.

Return type (Promise)

_returns

array of Tab

Details about the moved tabs.

query([queryInfo])

– [Added in TB 62]

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

Parameters

queryInfo

[queryInfo]

(object, optional)

active

[active]

(boolean, optional)

Whether the tabs are active in their windows.

cookieStoreId

[cookieStoreId]

(array of string or string, optional)

– [Added in TB 115]

The CookieStore id(s) used by the tabs. Either custom ids created using the contextualIdentities API, or built-in ones: firefox-default, firefox-container-1, firefox-container-2, firefox-container-3, firefox-container-4, firefox-container-5.

Note

The naming pattern of the built-in cookie stores was deliberately not changed for Thunderbird, but kept for compatibility reasons.

currentWindow

[currentWindow]

(boolean, optional)

Whether the tabs are in the current window.

highlighted

[highlighted]

(boolean, optional)

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

index

[index]

(integer, optional)

The position of the tabs within their windows.

lastFocusedWindow

[lastFocusedWindow]

(boolean, optional)

Whether the tabs are in the last focused window.

mailTab

[mailTab]

(boolean, optional)

– [Added in TB 66]

Whether the tab is a Thunderbird 3-pane tab. If specified, the queryInfo.type property will be ignored

spaceId

[spaceId]

(integer, optional)

– [Added in TB 115]

The id of the space the tabs should belong to.

status

[status]

(TabStatus, optional)

Whether the tabs have completed loading.

title

[title]

(string, optional)

Match page titles against a pattern.

type

[type]

(TabType or array of TabType, optional)

– [Added in TB 91]

Match tabs against the given tab type or types.

url

[url]

(string or array of string, optional)

Match tabs against one or more URL Patterns. Fragment identifiers are not matched.

windowId

[windowId]

(integer, optional)

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

windowType

[windowType]

(WindowType, optional)

The type of window the tabs are in.

Return type (Promise)

_returns

array of Tab

reload([tabId], [reloadProperties])

– [Added in TB 62]

Reload a tab. Only applicable for tabs which display a content page.

Parameters

tabId

[tabId]

(integer, optional)

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

reloadProperties

[reloadProperties]

(object, optional)

bypassCache

[bypassCache]

(boolean, optional)

Whether using any local cache. Default is false.

remove(tabIds)

– [Added in TB 62]

Closes one or more tabs.

Parameters

tabIds

tabIds

(integer or array of integer)

The tab or list of tabs to close.

removeCSS([tabId], details)

– [Added in TB 62]

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

Parameters

tabId

[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

Details of the CSS text to remove.

sendMessage(tabId, message, [options])

– [Added in TB 82]

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

tabId

(integer)

message

message

(any)

options

[options]

(object, optional)

frameId

[frameId]

(integer, optional)

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

Return type (Promise)

_returns

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.

update([tabId], updateProperties)

– [Added in TB 62]

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

Parameters

tabId

[tabId]

(integer, optional)

Defaults to the selected tab of the current window.

updateProperties

updateProperties

(object)

Properties which should to be updated.

active

[active]

(boolean, optional)

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

url

[url]

(string, optional)

A URL of a page to load. If the URL points to a content page (a web page, an extension page or a registered WebExtension protocol handler page), the tab will navigate to the requested page. All other URLs will be opened externally without changing the tab.

Note

This function will throw an error, if a content page is loaded into a non-content tab (its type must be either content or mail).

Return type (Promise)

_returns

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

Events

onActivated

– [Added in TB 62]

Fires when the active tab in a window changes. The tab’s URL may not be set at the time this event fired, listen to the onUpdated event instead to be notified when a URL is set.

Parameters for onActivated.addListener(listener)

listener(activeInfo)

listener(activeInfo)

A function that will be called when this event occurs.

Parameters passed to the listener function

activeInfo

activeInfo

(object)

tabId

tabId

(integer)

The ID of the tab that has become active.

windowId

windowId

(integer)

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

previousTabId

[previousTabId]

(integer, optional)

– [Added in TB 114]

The ID of the tab that was previously active, if that tab is still open.

onAttached

– [Added in TB 62]

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)

listener(tabId, attachInfo)

A function that will be called when this event occurs.

Parameters passed to the listener function

tabId

tabId

(integer)

attachInfo

attachInfo

(object)

newPosition

newPosition

(integer)

newWindowId

newWindowId

(integer)

onCreated

– [Added in TB 62]

Fired when a tab is created. The tab may still be loading, with its title being loading… and its URL being about:blank. To detect when the tab has finished loading, listen to the onUpdated event.

Parameters for onCreated.addListener(listener)

listener(tab)

listener(tab)

A function that will be called when this event occurs.

Parameters passed to the listener function

tab

tab

(Tab)

Details of the tab that was created.

onDetached

– [Added in TB 62]

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)

listener(tabId, detachInfo)

A function that will be called when this event occurs.

Parameters passed to the listener function

tabId

tabId

(integer)

detachInfo

detachInfo

(object)

oldPosition

oldPosition

(integer)

oldWindowId

oldWindowId

(integer)

onMoved

– [Added in TB 62]

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)

listener(tabId, moveInfo)

A function that will be called when this event occurs.

Parameters passed to the listener function

tabId

tabId

(integer)

moveInfo

moveInfo

(object)

fromIndex

fromIndex

(integer)

toIndex

toIndex

(integer)

windowId

windowId

(integer)

onRemoved

– [Added in TB 62]

Fired when a tab is closed.

Parameters for onRemoved.addListener(listener)

listener(tabId, removeInfo)

listener(tabId, removeInfo)

A function that will be called when this event occurs.

Parameters passed to the listener function

tabId

tabId

(integer)

removeInfo

removeInfo

(object)

isWindowClosing

isWindowClosing

(boolean)

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

windowId

windowId

(integer)

The window whose tab is closed.

onUpdated

– [Added in TB 62]

Fired when a tab is updated.

Parameters for onUpdated.addListener(listener, filter)

listener(tabId, changeInfo, tab)

listener(tabId, changeInfo, tab)

A function that will be called when this event occurs.

filter

[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

tabId

(integer)

changeInfo

changeInfo

(object)

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

favIconUrl

[favIconUrl]

(string, optional)

The tab’s new favicon URL.

status

[status]

(string, optional)

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

url

[url]

(string, optional)

The tab’s URL if it has changed.

tab

tab

(Tab)

Gives the state of the tab that was updated.

Types

CSSOrigin

– [Added in TB 53]

The origin of the CSS to inject, this affects the cascading order (priority) of the stylesheet.

string

Supported values:

author

author

user

user

InjectDetails

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

object

allFrames

[allFrames]

(boolean, optional)

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.

code

[code]

(string, optional)

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.

cssOrigin

[cssOrigin]

(CSSOrigin, optional)

The css origin of the stylesheet to inject. Defaults to “author”.

file

[file]

(string, optional)

JavaScript or CSS file to inject.

frameId

[frameId]

(integer, optional)

The ID of the frame to inject the script into. This may not be used in combination with allFrames.

matchAboutBlank

[matchAboutBlank]

(boolean, optional)

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.

runAt

[runAt]

(RunAt, optional)

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

RunAt

– [Added in TB 45]

The soonest that the JavaScript or CSS will be injected into the tab.

string

Supported values:

document_end

document_end

document_idle

document_idle

document_start

document_start

Tab

– [Added in TB 62]

object

active

active

(boolean)

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

highlighted

highlighted

(boolean)

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

index

index

(integer)

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

selected

selected

(boolean) Unsupported.

Whether the tab is selected.

cookieStoreId

[cookieStoreId]

(string, optional)

– [Added in TB 115]

The CookieStore id used by the tab. Either a custom id created using the contextualIdentities API, or a built-in one: firefox-default, firefox-container-1, firefox-container-2, firefox-container-3, firefox-container-4, firefox-container-5.

Note

The naming pattern of the built-in cookie stores was deliberately not changed for Thunderbird, but kept for compatibility reasons.

favIconUrl

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

groupId

[groupId]

(integer, optional)

– [Added in TB 138]

The ID of the group that the tab belongs to. -1 if the tab does not belong to a tab group.

height

[height]

(integer, optional)

The height of the tab in pixels.

id

[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

[mailTab]

(boolean, optional)

– [Added in TB 66]

Whether the tab is a 3-pane tab.

spaceId

[spaceId]

(integer, optional)

– [Added in TB 115]

The id of the space.

status

[status]

(string, optional)

Either loading or complete.

title

[title]

(string, optional)

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

type

[type]

(TabType, optional)

– [Added in TB 91]

url

[url]

(string, optional)

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

width

[width]

(integer, optional)

The width of the tab in pixels.

windowId

[windowId]

(integer, optional)

The ID of the window the tab is contained within.

TabStatus

– [Added in TB 62]

Whether the tabs have completed loading.

string

Supported values:

complete

complete

loading

loading

TabType

– [Added in TB 121]

Tab types supported by the tabs API.

string

Supported values:

addressBook

addressBook

calendar

calendar

calendarEvent

calendarEvent

calendarTask

calendarTask

chat

chat

content

content

mail

mail

messageCompose

messageCompose

messageDisplay

messageDisplay

special

special

tasks

tasks

UpdateFilter

– [Added in TB 62]

An object describing filters to apply to onUpdated events.

object

properties

[properties]

(array of UpdatePropertyName, optional)

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

tabId

[tabId]

(integer, optional)

urls

[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

[windowId]

(integer, optional)

UpdatePropertyName

– [Added in TB 62]

Event names supported in onUpdated.

string

Supported values:

favIconUrl

favIconUrl

status

status

title

title

WindowType

– [Added in TB 62]

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

string

Supported values:

app

app

devtools

devtools

messageCompose

messageCompose

– [Added in TB 88]

messageDisplay

messageDisplay

– [Added in TB 88]

normal

normal

panel

panel

popup

popup

Properties

TAB_ID_NONE

An ID which represents the absence of a tab.