windows

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.

Use the browser.windows API to interact with Thunderbird. You can use this API to create, modify, and rearrange windows.

Functions

get(windowId, [getInfo])

Gets details about a window.

Parameters

windowId

(integer)

[getInfo]

Return type (Promise)

getCurrent([getInfo])

Gets the current 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 browser with any optional sizing, position or default URL provided.

Parameters

[createData]

(object)

[allowScriptsToClose]

(boolean)

Allow scripts to close the window.

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

Whether the new window should be an incognito window.

[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. This value is ignored for panels.

[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. This value is ignored for panels.

[type]

Specifies what type of browser window to create. The ‘panel’ and ‘detached_panel’ types create a popup unless the ‘–enable-panels’ flag is set.

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

If true, causes 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. Set to false to cancel a previous draw attention request.

[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. This value is ignored for panels.

[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. This value is ignored for panels.

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 browser windows have lost focus. Note: On some Linux window managers, WINDOW_ID_NONE will always be sent immediately preceding a switch from one browser 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 browser window to create. The ‘panel’ and ‘detached_panel’ types create a popup unless the ‘–enable-panels’ flag is set.

string

Supported values:

normal

popup

panel

detached_panel

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.

[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 browser 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 populate 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 browser 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

popup

panel

app

devtools

addressBook

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

messageCompose

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

messageDisplay

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

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.