windows API

Note

These APIs are for the main Thunderbird windows which can contain webpage tabs and also other window types like composer or address books that cannot contain webpage tabs. Make sure your code interacts with windows appropriately, depending on their type.

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

Functions

get(windowId, [getInfo])

Gets details about a window.

Parameters

windowId

(integer)

[getInfo]

Return type (Promise)

getCurrent([getInfo])

Gets the active or topmost window.

Parameters

[getInfo]

Return type (Promise)

getLastFocused([getInfo])

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

Parameters

[getInfo]

Return type (Promise)

getAll([getInfo])

Gets all windows.

Parameters

[getInfo]

Return type (Promise)

array of Window

create([createData])

Creates (opens) a new window with any optional sizing, position or default URL provided.

Parameters

[createData]

(object)

[allowScriptsToClose]

(boolean)

Allow scripts running inside the window to close the window by calling window.close().

[focused]

(boolean) Unsupported.

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

[height]

(integer)

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

[incognito]

(boolean) Unsupported.

[left]

(integer)

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.

[state]

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

[tabId]

(integer)

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

[titlePreface]

(string)

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

[top]

(integer)

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]

(string or array of string)

A URL or array of URLs to open as tabs in the 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 current page within the extension. Defaults to the New Tab Page.

[width]

(integer)

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

Return type (Promise)

Contains details about the created window.

update(windowId, updateInfo)

Updates the properties of a window. Specify only the properties that you want to change; unspecified properties will be left unchanged.

Parameters

windowId

(integer)

updateInfo

(object)

[drawAttention]

(boolean)

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]

(boolean)

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

[height]

(integer)

The height to resize the window to in pixels.

[left]

(integer)

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]

(string)

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

[top]

(integer)

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

[width]

(integer)

The width to resize the window to in pixels.

Return type (Promise)

remove(windowId)

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

Parameters

windowId

(integer)

openDefaultBrowser(url)

– [Added in TB 84, backported to TB 78.6.0]

Opens the provided URL in the default system browser.

Parameters

url

(string)

Events

onCreated

Fired when a window is created.

Parameters for onCreated.addListener(listener)

listener(window)

A function that will be called when this event occurs.

Parameters passed to the listener function

window

(Window)

Details of the window that was created.

onRemoved

Fired when a window is removed (closed).

Parameters for onRemoved.addListener(listener)

listener(windowId)

A function that will be called when this event occurs.

Parameters passed to the listener function

windowId

(integer)

ID of the removed window.

onFocusChanged

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

(integer)

ID of the newly focused window.

Types

CreateType

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

string

Supported values:

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.

panel

Not supported, same as popup

detached_panel

Not supported, same as popup

GetInfo

Specifies additional requirements for the returned windows.

object

[populate]

(boolean)

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]

(array of WindowType)

If set, the Window returned will be filtered based on its type. Supported by getAll([getInfo]) only, ignored in all other functions.

Window

object

alwaysOnTop

(boolean)

Whether the window is set to be always on top.

focused

(boolean)

Whether the window is currently the focused window.

incognito

(boolean)

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

[height]

(integer)

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

[id]

(integer)

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

[left]

(integer)

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

[state]

The state of this window.

[tabs]

(array of Tab)

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]

(string)

The title of the window. Read-only.

[top]

(integer)

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

[type]

The type of window this is.

[width]

(integer)

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

WindowState

The state of this window.

string

Supported values:

normal

minimized

maximized

fullscreen

docked

WindowType

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

string

Supported values:

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.

panel

app

devtools

messageCompose

– [Added in TB 70, backported to TB 68.1.1]

A non-modal stand-alone message compose window.

messageDisplay

– [Added in TB 70, backported to TB 68.1.1]

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

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.