docs.rodeo

MDN Web Docs mirror

windows.create()

{{AddonSidebar}} 

Creates a new window.

When you create the window, you can:

This is an asynchronous function that returns a Promise.

Syntax

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

Parameters

Return value

A Promise that will be fulfilled with a {{WebExtAPIRef('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 {{WebExtAPIRef("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:

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:

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:

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);
});

{{WebExtExamples}} 

Browser compatibility

{{Compat}} 

[!NOTE] This API is based on Chromium’s chrome.windows API. This documentation is derived from windows.json in the Chromium code.

See also

In this article

View on MDN