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
Grant host permission to the currently active tab, allowing to read title, url and favIconUrl properties, or to inject content scripts.
contextualIdentities
Grant access to some or all methods of the contextualIdentities API.
cookies
Grant access to some or all methods of the cookies API.
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
connectInfo
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
Properties for the new tab. Defaults to an empty tab, if no url is provided.
active
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
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
permission is required to be able to specify this property. Furthermore, the permission should be requested, to enable the contextual identities feature (enabled by default only on Thunderbird Daily).index
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
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
relaxed
strict
selected
Whether the tab should become the selected tab in the window. Defaults to true
url
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
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.
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
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.
get(tabId)
– [Added in TB 62]
Retrieves details about the specified tab.
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).
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
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.
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
The tab or list of tabs to move.
moveProperties
query([queryInfo])
– [Added in TB 62]
Gets all tabs that have the specified properties, or all tabs if no properties are specified.
Parameters
queryInfo
active
Whether the tabs are active in their windows.
cookieStoreId
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
Whether the tabs are in the current window.
highlighted
Whether the tabs are highlighted. Works as an alias of active.
index
The position of the tabs within their windows.
lastFocusedWindow
Whether the tabs are in the last focused window.
mailTab
Whether the tab is a Thunderbird 3-pane tab. If specified, the queryInfo.type property will be ignored
spaceId
The id of the space the tabs should belong to.
status
title
Match page titles against a pattern.
type
Match tabs against the given tab type or types.
url
Match tabs against one or more URL Patterns. Fragment identifiers are not matched.
windowId
The ID of the parent window, or WINDOW_ID_CURRENT for the current window.
windowType
The type of window the tabs are in.
reload([tabId], [reloadProperties])
– [Added in TB 62]
Reload a tab. Only applicable for tabs which display a content page.
remove(tabIds)
– [Added in TB 62]
Closes one or more tabs.
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
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.
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
message
options
Return type (Promise)
_returns
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
Defaults to the selected tab of the current window.
updateProperties
Properties which should to be updated.
active
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
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).
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)
A function that will be called when this event occurs.
Parameters passed to the listener function
activeInfo
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)
A function that will be called when this event occurs.
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)
A function that will be called when this event occurs.
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)
A function that will be called when this event occurs.
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)
A function that will be called when this event occurs.
onRemoved
– [Added in TB 62]
Fired when a tab is closed.
Parameters for onRemoved.addListener(listener)
listener(tabId, removeInfo)
A function that will be called when this event occurs.
onUpdated
– [Added in TB 62]
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
changeInfo
tab
Types
CSSOrigin
– [Added in TB 53]
The origin of the CSS to inject, this affects the cascading order (priority) of the stylesheet.
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
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
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
The css origin of the stylesheet to inject. Defaults to “author”.
file
JavaScript or CSS file to inject.
frameId
The ID of the frame to inject the script into. This may not be used in combination with allFrames.
matchAboutBlank
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
– [Added in TB 45]
The soonest that the JavaScript or CSS will be injected into the tab.
Tab
– [Added in TB 62]
object
active
Whether the tab is active in its window. (Does not necessarily mean the window is focused.)
highlighted
Whether the tab is highlighted. Works as an alias of active
index
The zero-based index of the tab within its window.
selected
Whether the tab is selected.
cookieStoreId
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
The URL of the tab’s favicon. This property is only present if the extension’s manifest includes the
permission. It may also be an empty string if the tab is loading.groupId
The ID of the group that the tab belongs to. -1 if the tab does not belong to a tab group.
height
The height of the tab in pixels.
id
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
Whether the tab is a 3-pane tab.
spaceId
The id of the space.
status
Either loading or complete.
title
The title of the tab. This property is only present if the extension’s manifest includes the
permission.type
url
The URL the tab is displaying. This property is only present if the extension’s manifest includes the
permission.width
The width of the tab in pixels.
windowId
The ID of the window the tab is contained within.
TabStatus
– [Added in TB 62]
Whether the tabs have completed loading.
TabType
– [Added in TB 121]
Tab types supported by the tabs API.
UpdateFilter
– [Added in TB 62]
An object describing filters to apply to onUpdated events.
object
properties
A list of property names. Events that do not match any of the names will be filtered out.
tabId
urls
A list of URLs or URL patterns. Events that cannot match any of the URLs will be filtered out. Filtering with urls requires the
or permission.windowId
UpdatePropertyName
– [Added in TB 62]
Event names supported in onUpdated.
WindowType
– [Added in TB 62]
The type of a window. Under some circumstances a Window may not be assigned a type property.
Properties
TAB_ID_NONE
An ID which represents the absence of a tab.