1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
---
title: tabs.hide()
slug: Mozilla/Add-ons/WebExtensions/API/tabs/hide
translation_of: Mozilla/Add-ons/WebExtensions/API/tabs/hide
---
<div>{{AddonSidebar()}}</div>
<p>Hides one or more tabs.</p>
<p>Hidden tabs are no longer visible in the browser's tabstrip. Hidden tabs are not automatically <a href="/en-US/Add-ons/WebExtensions/API/tabs/discard">discarded</a>: 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.</p>
<p>This is an asynchronous function that returns a <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></code>.</p>
<p>Not all tabs are eligible for being hidden:</p>
<ul>
<li>Tabs that are pinned cannot be hidden.</li>
<li>Tabs that are sharing the screen, microphone or camera cannot be hidden.</li>
<li>The current active tab cannot be hidden.</li>
<li>Tabs that are in the process of being closed cannot be hidden.</li>
</ul>
<p>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.</p>
<p>To use this API you must have the "tabHide" <a href="/en-US/Add-ons/WebExtensions/manifest.json/permissions">permission</a>.</p>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox brush:js">var hiding = browser.tabs.hide(
tabIds // integer or integer array
)
</pre>
<h3 id="Parameters">Parameters</h3>
<dl>
<dt><code>tabIds</code></dt>
<dd><code><code>integer</code></code> or <code><code>array</code></code> of <code><code>integer</code></code>. The IDs of the tab or tabs to hide.</dd>
<dd>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 <code>[1, 3]</code>, and <code>1</code> identifies the active tab, then only <code>3</code> will be hidden.</dd>
<dd>However, if any of the tab IDs are invalid, the call will fail and no tabs will be hidden.</dd>
</dl>
<h3 id="Return_value">Return value</h3>
<p>A <code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></code> 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.</p>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{Compat}}</p>
<h2 id="Examples">Examples</h2>
<p>Hide a single tab:</p>
<pre class="brush: js">function onHidden() {
console.log(`Hidden`);
}
function onError(error) {
console.log(`Error: ${error}`);
}
browser.tabs.hide(2).then(onHidden, onError);</pre>
<p>Hide multiple tabs:</p>
<pre class="brush: js">function onHidden() {
console.log(`Hidden`);
}
function onError(error) {
console.log(`Error: ${error}`);
}
browser.tabs.hide([15, 14, 1]).then(onHidden, onError);</pre>
<p>{{WebExtExamples}}</p>
|