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

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

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

[createData]

(object, optional)

allowScriptsToClose

[allowScriptsToClose]

(boolean, optional)

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

[cookieStoreId]

(string, optional)

– [Added in TB 115]

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

focused

[focused]

(boolean, optional) Unsupported.

If true, opens an active window. If false, opens an inactive window.

height

[height]

(integer, optional)

The height in pixels of the new window, including the frame. If not specified defaults to a natural height.

incognito

[incognito]

(boolean, optional) Unsupported.

left

[left]

(integer, optional)

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

[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

state

[state]

(WindowState, optional)

The initial state of the window. The minimized, maximized and fullscreen states cannot be combined with left, top, width or height.

tabId

[tabId]

(integer, optional)

The id of the tab for which you want to adopt to the new window.

titlePreface

[titlePreface]

(string, optional)

A string to add to the beginning of the window title.

top

[top]

(integer, optional)

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

[type]

(CreateType, optional)

Specifies what type of window to create. Thunderbird does not support panel and detached_panel, they are interpreted as popup.

url

[url]

(string or array of string, optional)

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

[width]

(integer, optional)

The width in pixels of the new window, including the frame. If not specified defaults to a natural width.

Return type (Promise)

_returns

Contains details about the created window.

get(windowId, [getInfo])

– [Added in TB 62]

Gets details about a window.

Parameters

windowId

windowId

(integer)

getInfo

[getInfo]

(GetInfo, optional)

Return type (Promise)

_returns

getAll([getInfo])

– [Added in TB 62]

Gets all windows.

Parameters

getInfo

[getInfo]

(GetInfo, optional)

Return type (Promise)

_returns

array of Window

getCurrent([getInfo])

– [Added in TB 62]

Gets the active or topmost window.

Parameters

getInfo

[getInfo]

(GetInfo, optional)

Return type (Promise)

_returns

getLastFocused([getInfo])

– [Added in TB 62]

Gets the window that was most recently focused — typically the window ‘on top’.

Parameters

getInfo

[getInfo]

(GetInfo, optional)

Return type (Promise)

_returns

openDefaultBrowser(url)

– [Added in TB 85]

Opens the provided URL in the default system browser.

Parameters

url

url

(string)

remove(windowId)

– [Added in TB 62]

Removes (closes) a window, and all the tabs inside it.

Parameters

windowId

windowId

(integer)

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

windowId

(integer)

updateInfo

updateInfo

(object)

drawAttention

[drawAttention]

(boolean, optional)

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

[focused]

(boolean, optional)

If true, brings the window to the front. If false, brings the next window in the z-order to the front.

height

[height]

(integer, optional)

The height to resize the window to in pixels.

left

[left]

(integer, optional)

The offset from the left edge of the screen to move the window to in pixels. This value is ignored for panels.

state

[state]

(WindowState, optional)

The new state of the window. The minimized, maximized and fullscreen states cannot be combined with left, top, width or height.

titlePreface

[titlePreface]

(string, optional)

A string to add to the beginning of the window title.

top

[top]

(integer, optional)

The offset from the top edge of the screen to move the window to in pixels. This value is ignored for panels.

width

[width]

(integer, optional)

The width to resize the window to in pixels.

Return type (Promise)

_returns

Events

onCreated

– [Added in TB 62]

Fired when a window is created.

Parameters for onCreated.addListener(listener)

listener(window)

listener(window)

A function that will be called when this event occurs.

Parameters passed to the listener function

window

window

(Window)

Details of the window that was created.

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)

listener(windowId)

A function that will be called when this event occurs.

Parameters passed to the listener function

windowId

windowId

(integer)

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)

listener(windowId)

A function that will be called when this event occurs.

Parameters passed to the listener function

windowId

windowId

(integer)

ID of the removed window.

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.

string

Supported values:

detached_panel

detached_panel

Not supported, same as popup

normal

normal

A normal Thunderbird window, a.k.a. 3-pane-window (folder pane, message pane and preview pane).

panel

panel

Not supported, same as popup

popup

popup

A non-modal stand-alone popup window.

GetInfo

– [Added in TB 78]

Specifies additional requirements for the returned windows.

object

populate

[populate]

(boolean, optional)

If true, the Window returned will have a tabs property that contains an array of Tab objects representing the tabs inside the window. The Tab objects only contain the url, title and favIconUrl properties if the extension’s manifest file includes the tabs permission.

windowTypes

[windowTypes]

(array of WindowType, optional)

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

alwaysOnTop

(boolean)

Whether the window is set to be always on top.

focused

focused

(boolean)

Whether the window is currently the focused window.

incognito

incognito

(boolean)

Whether the window is incognito. Since Thunderbird does not support the incognito mode, this is always false.

height

[height]

(integer, optional)

The height of the window, including the frame, in pixels.

id

[id]

(integer, optional)

The ID of the window. Window IDs are unique within a session.

left

[left]

(integer, optional)

The offset of the window from the left edge of the screen in pixels.

state

[state]

(WindowState, optional)

The state of this window.

tabs

[tabs]

(array of Tab, optional)

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

[title]

(string, optional)

The title of the window. Read-only.

top

[top]

(integer, optional)

The offset of the window from the top edge of the screen in pixels.

type

[type]

(WindowType, optional)

The type of window this is.

width

[width]

(integer, optional)

The width of the window, including the frame, in pixels.

WindowState

– [Added in TB 62]

The state of this window.

string

Supported values:

docked

docked

fullscreen

fullscreen

maximized

maximized

minimized

minimized

normal

normal

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

messageCompose

– [Added in TB 70]

A non-modal stand-alone message compose window.

messageDisplay

messageDisplay

– [Added in TB 70]

A non-modal stand-alone message display window, viewing a single message.

normal

normal

A normal Thunderbird window, a.k.a. 3-pane-window (folder pane, message pane and preview pane).

popup

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.