MDN wants to learn about developers like you: https://qsurvey.mozilla.com/s3/MDN-survey

Add-ons

tabs.hide()

Note that this currently an experimental API: it may be changed or removed at any time.

It is only supported in Firefox and is disabled by default. To enable it, visit about:config and set "extensions.webextensions.tabhide.enabled" to true.

Hides one or more tabs.

Hidden tabs are no longer visible in the browser's tabstrip. Hidden tabs are not automatically discarded: the code running in them continues to run. However, it's recommended that you should also discard hidden tabs, to help manage memory and resource usage.

This is an asynchronous function that returns a Promise.

Not all tabs are eligible for being hidden:

  • Tabs that are pinned cannot be hidden.
  • Tabs that are sharing the screen, microphone or camera cannot be hidden.
  • The current active tab cannot be hidden.
  • Tabs that are in the process of being closed cannot be hidden.

To use this API you must have the "tabHide" permission.

Syntax

var hiding = browser.tabs.hide(
  tabIds          // integer or integer array
)

Parameters

tabIds
integer or array of integer. The IDs of the tab or tabs to hide.
If any of these tabs are not eligible for being hidden, they will not be hidden, but the call will still succeed and eligible tabs will still be hidden. For example, if you pass [1, 3], and 1 identifies the active tab, then only 3 will be hidden.
However, if any of the tab IDs are invalid, the call will fail and no tabs will be hidden.

Return value

A Promise that will be fulfilled with an array containing the IDs of the tabs that were hidden. If any error occurs, the promise will be rejected with an error message.

Browser compatibility

No compatibility data found. Please contribute data for "webextensions.api.tabs.hide" (depth: 1) to the MDN compatibility data repository.

Examples

Hide a single tab:

function onHidden() {
  console.log(`Hidden`);
}

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

browser.tabs.hide(2).then(onHidden, onError);

Hide multiple tabs:

function onHidden() {
  console.log(`Hidden`);
}

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

browser.tabs.hide([15, 14, 1]).then(onHidden, onError);

Document Tags and Contributors

 Contributors to this page: wbamberg
 Last updated by: wbamberg,