windows.create()

Creates a new window.

When you create the window, you can:

  • Load one or more new tabs into the window.
  • Move a tab from an existing window into the new window.
  • Set the size and position of the window.
  • Create a "panel" style window, which in this context means a window without any of the normal browser UI (address bar, toolbar, etc.).
  • Set various properties of the window, such as whether it is focused or private.

This is an asynchronous function that returns a Promise.

Syntax

js
let creating = browser.windows.create(
  createData            // optional object
)

Parameters

createData Optional

object.

allowScriptsToClose Optional

boolean. When the window is opened, it will contain a single tab, or more than one tab if url is given and includes an array containing more than one URL. By default scripts running in these pages are not allowed to close their tab using window.close(). If you include allowScriptsToClose and set it to true, then this default behavior is changed, so scripts can close their tabs. Note that:

  • this only applies to the tabs that were opened when the window was created. If the user opens more tabs in this window, then scripts will not be able to close those new tabs.
  • if the URL(s) given in url point to extension pages (that is, they are pages included with this extension and loaded with the "moz-extension:" protocol) then scripts are by default allowed to close those tabs.
cookieStoreId Optional

integer. If present, specifies the CookieStoreId for all the tabs created when the window is opened. See Work with contextual identities for more information on using cookieStoreId.

focused Optional

boolean. If true, the new window will be focused. If false, the new window will be opened in the background and the currently focused window will stay focused. Defaults to true.

height Optional

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

incognito Optional

boolean. Whether the new window should be an incognito (private) window. Note that if you specify incognito and tabId, the ID must refer to a private tab — that is, you can't move a non-private tab to a private window.

left Optional

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. (Ignored in Firefox 108 or earlier for panel or popup window types; positioning the window using windows.update() could be used as a workaround.)

state Optional

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

tabId Optional

integer. If included, moves a tab of the specified ID from an existing window into the new window.

titlePreface Optional

string. Use this to add a string to the beginning of the browser window's title. Depending on the underlying operating system, this might not work on browser windows that don't have a title (such as about:blank in Firefox).

top Optional

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. (Ignored in Firefox 108 or earlier for panel or popup window types; positioning the window using windows.update() could be used as a workaround.)

type Optional

A windows.CreateType value. Specifies what type of browser window to create. Specify panel or popup here to open a window without any of the normal browser UI (address bar, toolbar, etc.).

url Optional

string or array of strings. 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 Optional

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

Return value

A Promise that will be fulfilled with a windows.Window object containing the details of the new window. This Window object will always have its tabs property set, unlike the Window objects returned from windows.get() and similar APIs, which only contain tabs if the populate option is passed. If any error occurs, the promise will be rejected with an error message.

Examples

Open a window containing two tabs:

js
function onCreated(windowInfo) {
  console.log(`Created window: ${windowInfo.id}`);
}

function onError(error) {
  console.log(`Error: ${error}`);
}

browser.browserAction.onClicked.addListener((tab) => {
  let creating = browser.windows.create({
    url: ["https://developer.mozilla.org", "https://addons.mozilla.org"],
  });
  creating.then(onCreated, onError);
});

Open a window when the user clicks a browser action, and move the currently active tab into it:

js
function onCreated(windowInfo) {
  console.log(`Created window: ${windowInfo.id}`);
}

function onError(error) {
  console.log(`Error: ${error}`);
}

browser.browserAction.onClicked.addListener((tab) => {
  let creating = browser.windows.create({
    tabId: tab.id,
  });
  creating.then(onCreated, onError);
});

Open a small panel-style window, and load a locally-packaged file into it:

js
function onCreated(windowInfo) {
  console.log(`Created window: ${windowInfo.id}`);
}

function onError(error) {
  console.log(`Error: ${error}`);
}

browser.browserAction.onClicked.addListener((tab) => {
  let popupURL = browser.extension.getURL("popup/popup.html");

  let creating = browser.windows.create({
    url: popupURL,
    type: "popup",
    height: 200,
    width: 200,
  });
  creating.then(onCreated, onError);
});

Example extensions

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
create
Chrome – Full support
Chrome 4 (Release date: 2010-01-25)
footnote
footnote top, bottom, left, right bounds must be at least 50% within visible screen space if specified, otherwise an error is thrown.
Edge – Full support
Edge 14 (Release date: 2016-08-02)
footnote Full support
Firefox – Full support
Firefox 45 (Release date: 2016-03-08)
footnote
footnote url and tabId options can't be set together.
footnote The returned Window object contains the tabs property only from version 52 onwards.
footnote In Firefox 85 and earlier, focused: false is unsupported and throws an error. From Firefox 86, focused: false is ignored.
footnote From Firefox 109, top and left are used to determine window placement; previously, they were ignored.
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote
footnote top, bottom, left, right bounds must be at least 50% within visible screen space if specified, otherwise an error is thrown.
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
createData
Chrome – Full support
Chrome 4 (Release date: 2010-01-25)
footnote Full support
Edge – Full support
Edge 14 (Release date: 2016-08-02)
footnote Full support
Firefox – Full support
Firefox 45 (Release date: 2016-03-08)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
createData.allowScriptsToClose
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 52 (Release date: 2017-03-07)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
createData.cookieStoreId
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 64 (Release date: 2018-12-11)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
createData.focused
Chrome – Full support
Chrome 12 (Release date: 2011-06-07)
footnote Full support
Edge – Full support
Edge 14 (Release date: 2016-08-02)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
createData.height
Chrome – Full support
Chrome 4 (Release date: 2010-01-25)
footnote Full support
Edge – Full support
Edge 14 (Release date: 2016-08-02)
footnote Full support
Firefox – Full support
Firefox 45 (Release date: 2016-03-08)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
createData.incognito
Chrome – Full support
Chrome 5 (Release date: 2010-05-25)
footnote Full support
Edge – Full support
Edge 14 (Release date: 2016-08-02)
footnote Full support
Firefox – Full support
Firefox 45 (Release date: 2016-03-08)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
createData.left
Chrome – Full support
Chrome 4 (Release date: 2010-01-25)
footnote Full support
Edge – Full support
Edge 14 (Release date: 2016-08-02)
footnote Full support
Firefox – Full support
Firefox 45 (Release date: 2016-03-08)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
createData.state
Chrome – Full support
Chrome 44 (Release date: 2015-07-21)
footnote Full support
Edge – Full support
Edge 14 (Release date: 2016-08-02)
footnote Full support
Firefox – Full support
Firefox 45 (Release date: 2016-03-08)
footnote Full support
Opera – Full support
Opera 31 (Release date: 2015-08-04)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
createData.tabId
Chrome – Full support
Chrome 10 (Release date: 2011-03-08)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 45 (Release date: 2016-03-08)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – No support
Safari
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
createData.titlePreface
Chrome – No support
Chrome
footnote No support
Edge – No support
Edge
footnote No support
Firefox – Full support
Firefox 56 (Release date: 2017-09-28)
footnote Full support
Opera – No support
Opera
footnote No support
Safari – No support
Safari
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
createData.top
Chrome – Full support
Chrome 4 (Release date: 2010-01-25)
footnote Full support
Edge – Full support
Edge 14 (Release date: 2016-08-02)
footnote Full support
Firefox – Full support
Firefox 45 (Release date: 2016-03-08)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
createData.type
Chrome – Full support
Chrome 5 (Release date: 2010-05-25)
footnote Full support
Edge – Full support
Edge 14 (Release date: 2016-08-02)
footnote Full support
Firefox – Full support
Firefox 45 (Release date: 2016-03-08)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
createData.url
Chrome – Full support
Chrome 4 (Release date: 2010-01-25)
footnote Full support
Edge – Full support
Edge 14 (Release date: 2016-08-02)
footnote Full support
Firefox – Full support
Firefox 45 (Release date: 2016-03-08)
footnote
footnote 'url' does not accept relative paths.
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support
createData.width
Chrome – Full support
Chrome 4 (Release date: 2010-01-25)
footnote Full support
Edge – Full support
Edge 14 (Release date: 2016-08-02)
footnote Full support
Firefox – Full support
Firefox 45 (Release date: 2016-03-08)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
See implementation notes.

Note: This API is based on Chromium's chrome.windows API. This documentation is derived from windows.json in the Chromium code.

See also