docs.rodeo

MDN Web Docs mirror

tabs.update()

{{AddonSidebar}} 

Navigate the tab to a new URL, or modify other properties of the tab.

To use this function, pass the ID of the tab to update, and an updateProperties object containing the properties you want to update. Properties that are not specified in updateProperties are not modified.

This is an asynchronous function that returns a Promise.

Syntax

let updating = browser.tabs.update(
  tabId,              // optional integer
  updateProperties    // object
)

Parameters

Return value

A Promise that will be fulfilled with a {{WebExtAPIRef('tabs.Tab')}}  object containing details about the updated tab. The {{WebExtAPIRef('tabs.Tab')}}  object doesn’t contain url, title and favIconUrl unless matching host permissions or the "tabs" permission has been requested. If the tab could not be found or some other error occurs, the promise will be rejected with an error message.

Examples

Navigate the active tab in the current window to https://developer.mozilla.org:

function onUpdated(tab) {
  console.log(`Updated tab: ${tab.id}`);
}

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

let updating = browser.tabs.update({ url: "https://developer.mozilla.org" });
updating.then(onUpdated, onError);

Activate the first tab in the current window, and navigate it to https://developer.mozilla.org:

function onUpdated(tab) {
  console.log(`Updated tab: ${tab.id}`);
}

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

function updateFirstTab(tabs) {
  let updating = browser.tabs.update(tabs[0].id, {
    active: true,
    url: "https://developer.mozilla.org",
  });
  updating.then(onUpdated, onError);
}

let querying = browser.tabs.query({ currentWindow: true });
querying.then(updateFirstTab, 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