docs.rodeo

MDN Web Docs mirror

tabs.create()

{{AddonSidebar}} 

Creates a new tab.

This is an asynchronous function that returns a Promise.

Syntax

let creating = browser.tabs.create(
  createProperties   // object
)

Parameters

Return value

A Promise that will be fulfilled with a {{WebExtAPIRef('tabs.Tab')}}  object containing details about the created tab. If the tab could not be created (for example, because url used a privileged scheme) the promise will be rejected with an error message.

The promise returned by browser.tabs.create() resolves as soon as the tab has been created. The tab may still be loading. To detect when the tab has finished loading, listen to the {{WebExtAPIRef('tabs.onUpdated')}}  or the {{WebExtAPIRef('webNavigation.onCompleted')}}  event before calling tabs.create.

Examples

Open “https://example.org” in a new tab:

function onCreated(tab) {
  console.log(`Created new tab: ${tab.id}`);
}

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

browser.browserAction.onClicked.addListener(() => {
  let creating = browser.tabs.create({
    url: "https://example.org",
  });
  creating.then(onCreated, onError);
});

{{WebExtExamples}} 

Browser compatibility

{{Compat}} 

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

In this article

View on MDN