windows API
The windows API supports creating, modifying and interacting with Thunderbird windows.
Note
This API can be used with Thunderbird’s main window and popup windows, both of which support web tabs, as well as with other window types like the composer window, which does not. Ensure your code handles each window type appropriately based on its capabilities.
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.
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
create([createData])
– [Added in TB 62]
Creates (opens) a new window with any optional sizing, position or default URL provided. When loading a page into a popup window, same-site links are opened within the same window, 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. Same-site links with targets other than _self are opened in a new tab in the most recent normal Thunderbird window.
Parameters
createData
allowScriptsToClose
Allow scripts running inside the window to close the window by calling window.close(). Defaults to true when the given URL points to an extension page (a page included with this extension and loaded with the moz-extension: protocol), defaults to false otherwise.
cookieStoreId
The CookieStore id which all initially opened tabs 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).focused
If true, opens an active window. If false, opens an inactive window.
height
The height in pixels of the new window, including the frame. If not specified defaults to a natural height.
incognito
left
The number of pixels to position the new window from the left edge of the screen. If not specified, the new window is offset naturally from the last focused 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
state
The initial state of the window. The minimized, maximized and fullscreen states cannot be combined with left, top, width or height.
tabId
The id of the tab for which you want to adopt to the new window.
titlePreface
A string to add to the beginning of the window title.
top
The number of pixels to position the new window from the top edge of the screen. If not specified, the new window is offset naturally from the last focused window.
type
Specifies what type of window to create. Thunderbird does not support panel and detached_panel, they are interpreted as popup.
url
A URL to be opened in a popup window, ignored in all other window types. This may also be an array, but only the first element is used (popup windows may not have multiple tabs). If the URL points to a content page (a web page, an extension page or a registered WebExtension protocol handler page), the popup window will navigate to the requested page. All other URLs will be opened externally after creating an empty popup window. 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. Defaults to the New Tab Page.
width
The width in pixels of the new window, including the frame. If not specified defaults to a natural width.
get(windowId, [getInfo])
– [Added in TB 62]
Gets details about a window.
getAll([getInfo])
– [Added in TB 62]
Gets all windows.
getCurrent([getInfo])
– [Added in TB 62]
Gets the active or topmost window.
getLastFocused([getInfo])
– [Added in TB 62]
Gets the window that was most recently focused — typically the window ‘on top’.
openDefaultBrowser(url)
– [Added in TB 85]
Opens the provided URL in the default system browser.
remove(windowId)
– [Added in TB 62]
Removes (closes) a window, and all the tabs inside it.
update(windowId, updateInfo)
– [Added in TB 62]
Updates the properties of a window. Specify only the properties that you want to change; unspecified properties will be left unchanged.
Parameters
windowId
updateInfo
drawAttention
Setting this to true will cause the window to be displayed in a manner that draws the user’s attention to the window, without changing the focused window. The effect lasts until the user changes focus to the window. This option has no effect if the window already has focus.
focused
If true, brings the window to the front. If false, brings the next window in the z-order to the front.
height
The height to resize the window to in pixels.
left
The offset from the left edge of the screen to move the window to in pixels. This value is ignored for panels.
state
The new state of the window. The minimized, maximized and fullscreen states cannot be combined with left, top, width or height.
titlePreface
A string to add to the beginning of the window title.
top
The offset from the top edge of the screen to move the window to in pixels. This value is ignored for panels.
width
The width to resize the window to in pixels.
Events
onCreated
– [Added in TB 62]
Fired when a window is created.
Parameters for onCreated.addListener(listener)
listener(window)
A function that will be called when this event occurs.
onFocusChanged
– [Added in TB 62]
Fired when the currently focused window changes. Will be WINDOW_ID_NONE, if all windows have lost focus.
Note
On some Linux window managers, WINDOW_ID_NONE will always be sent immediately preceding a switch from one window to another.
Parameters for onFocusChanged.addListener(listener)
listener(windowId)
A function that will be called when this event occurs.
Parameters passed to the listener function
windowId
ID of the newly focused window.
onRemoved
– [Added in TB 62]
Fired when a window is removed (closed).
Parameters for onRemoved.addListener(listener)
listener(windowId)
A function that will be called when this event occurs.
Types
CreateType
– [Added in TB 62]
Specifies what type of window to create. Thunderbird does not support panel and detached_panel, they are interpreted as popup.
GetInfo
– [Added in TB 78]
Specifies additional requirements for the returned windows.
object
populate
windowTypes
If set, the Window returned will be filtered based on its type. Supported by getAll([getInfo]) only, ignored in all other functions.
Window
– [Added in TB 62]
object
alwaysOnTop
Whether the window is set to be always on top.
focused
Whether the window is currently the focused window.
incognito
Whether the window is incognito. Since Thunderbird does not support the incognito mode, this is always false.
height
The height of the window, including the frame, in pixels.
id
The ID of the window. Window IDs are unique within a session.
left
The offset of the window from the left edge of the screen in pixels.
state
The state of this window.
tabs
Array of Tab objects representing the current tabs in the window. Only included if requested by get(windowId, [getInfo]), getCurrent([getInfo]), getAll([getInfo]) or getLastFocused([getInfo]), and the optional GetInfo parameter has its populate member set to true.
title
The title of the window. Read-only.
top
The offset of the window from the top edge of the screen in pixels.
type
The type of window this is.
width
The width of the window, including the frame, in pixels.
WindowState
– [Added in TB 62]
The state of this window.
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:
messageCompose
A non-modal stand-alone message compose window.
messageDisplay
A non-modal stand-alone message display window, viewing a single message.
normal
A normal Thunderbird window, a.k.a. 3-pane-window (folder pane, message pane and preview pane).
popup
A non-modal stand-alone popup window.
Properties
WINDOW_ID_CURRENT
The windowId value that represents the current window.
WINDOW_ID_NONE
The windowId value that represents the absence of a window.