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. You can explicitly discard tabs whenever you hide them: although this is not appropriate in all situations, it will help to reduce the resources used by the browser.
This is an asynchronous function that returns a Promise
.
Not all tabs are eligible for being hidden:
The first time an extension hides a tab, the browser will tell the user that the tab is being hidden, show them how they can access the hidden tab, and give them the option of disabling the extension instead.
To use this API you must have the "tabHide" permission.
var hiding = browser.tabs.hide( tabIds // integer or integer array )
tabIds
integer
or array
of integer
. The IDs of the tab or tabs to hide.[1, 3]
, and 1
identifies the active tab, then only 3
will be hidden.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.
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);
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
hide |
No |
No |
61 |
? |
No |
No |
? |
? |
No |
? |
? |
? |
© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/tabs/hide