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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
---
title: 选项卡. 查询 ()
slug: Mozilla/Add-ons/WebExtensions/API/tabs/query
translation_of: Mozilla/Add-ons/WebExtensions/API/tabs/query
original_slug: Mozilla/Add-ons/WebExtensions/API/tabs/查询
---
<div>[阿登侧边栏()]</div>
<p>获取具有指定属性的所有选项卡,如果未指定任何属性,则获取所有选项卡。</p>
<p><font>这是返回 的异步函数。</font><code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></code></p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox brush:js notranslate">let querying = browser.tabs.query(<var>queryObj</var>)
</pre>
<h3 id="参数">参数</h3>
<dl>
<dt><code><var>queryObj</var></code></dt>
<dd>
<p><code>object</code><font>.函数将仅获取其属性与此处包含的属性匹配的选项卡。</font><code>query()</code></p>
<p>请参阅 \WebExtAPIRef("选项卡")。Tab")=文档以了解有关这些属性的详细信息。</p>
<dl class="reference-values">
<dt><code>active</code><font>[optional_inline]</font></dt>
<dd><code>boolean</code><font>.选项卡是否在窗口中处于活动状态。</font></dd>
<dt><code>audible</code><font>[optional_inline]</font></dt>
<dd><code>boolean</code><font>.标签是否可听见。</font></dd>
<dt><code>autoDiscardable</code><font>[optional_inline]</font></dt>
<dd><code>boolean</code><font>.当资源不足时,浏览器是否可以自动丢弃选项卡。</font></dd>
<dt><code>cookieStoreId</code><font>[optional_inline]</font></dt>
<dd><code>string</code><font>.使用此仅返回其 Cookie 存储 ID 为 的选项卡。此选项仅在加载项具有权限时<a href="https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions">才可用</a>。</font><code>cookieStoreId</code><code>"cookies"</code></dd>
<dt><code>currentWindow</code><font>[optional_inline]</font></dt>
<dd><code>boolean</code><font>.选项卡是否在当前窗口中。</font></dd>
<dt><code>discarded</code><font>[optional_inline]</font></dt>
<dd><code>boolean</code><font>.是否丢弃选项卡。丢弃的选项卡是其内容已从内存中卸载,但仍在选项卡条中可见的选项卡。下次激活时,其内容将重新加载。</font></dd>
<dt><code>hidden</code><font>[optional_inline]</font></dt>
<dd><code>boolean</code><font>.选项卡是否隐藏。</font></dd>
<dt><code>highlighted</code><font>[optional_inline]</font></dt>
<dd><code>boolean</code><font>.选项卡是否突出显示。</font></dd>
<dt><code>index</code><font>[optional_inline]</font></dt>
<dd><code>integer</code><font>.选项卡在其窗口中的位置。</font></dd>
<dt><code>muted</code><font>[optional_inline]</font></dt>
<dd><code>boolean</code><font>.选项卡是否为静音。</font></dd>
<dt><code>lastFocusedWindow</code><font>[optional_inline]</font></dt>
<dd><code>boolean</code><font>.选项卡是否在上一个焦点窗口中。</font></dd>
<dt><code>pinned</code><font>[optional_inline]</font></dt>
<dd><code>boolean</code><font>.选项卡是否固定。</font></dd>
<dt><code>status</code><font>[optional_inline]</font></dt>
<dd>{WebExtAPIRef('选项卡。TabStatus ')=。选项卡是否已完成加载。</dd>
<dt><code>title</code><font>[optional_inline]</font></dt>
<dd><code>string</code><font>.将页面标题与图案匹配。</font></dd>
<dt><code>url</code><font>[optional_inline]</font></dt>
<dd><code><code>string</code></code><font>或。将选项卡与一个或多个匹配<a href="/en-US/docs/Mozilla/Add-ons/WebExtensions/Match_patterns">模式匹配</a>。请注意,片段标识符不匹配。</font><code><code>array</code> of <code><code>string</code></code></code></dd>
<dt><code>windowId</code><font>{{optional_inline}}</font></dt>
<dd><code>integer</code><font>. The of the parent window, or {{WebExtAPIRef('windows.WINDOW_ID_CURRENT')}} for the current window.</font><code>id</code></dd>
<dt><code>windowType</code><font>{{optional_inline}}</font></dt>
<dd>{{WebExtAPIRef('tabs.WindowType')}}. The type of window the tabs are in.</dd>
</dl>
</dd>
</dl>
<h3 id="Return_value">Return value</h3>
<p><font>A that will be fulfilled with an of objects, containing information about each matching tab.</font><code><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></code><code>array</code><code>{{WebExtAPIRef('tabs.Tab')}}</code></p>
<p>If any error occurs, the promise will be rejected with an error message.</p>
<h2 id="Examples">Examples</h2>
<p>Get all tabs:</p>
<pre class="brush: js notranslate">function logTabs(tabs) {
for (let tab of tabs) {
// tab.url requires the `tabs` permission
console.log(tab.url);
}
}
function onError(error) {
console.log(`Error: ${error}`);
}
let querying = browser.tabs.query({});
querying.then(logTabs, onError);</pre>
<p>Get all tabs in the current window:</p>
<pre class="brush: js notranslate">function logTabs(tabs) {
for (let tab of tabs) {
// tab.url requires the `tabs` permission
console.log(tab.url);
}
}
function onError(error) {
console.log(`Error: ${error}`);
}
let querying = browser.tabs.query({currentWindow: true});
querying.then(logTabs, onError);</pre>
<p>Get the active tab in the current window:</p>
<pre class="brush: js notranslate">function logTabs(tabs) {
// tabs[0].url requires the `tabs` permission
console.log(tabs[0].url);
}
function onError(error) {
console.log(`Error: ${error}`);
}
let querying = browser.tabs.query({currentWindow: true, active: true});
querying.then(logTabs, onError);</pre>
<p><font>Get tabs for all HTTP and HTTPS URLs under or any of its subdomains:</font><code>"mozilla.org"</code></p>
<pre class="brush: js notranslate">function logTabs(tabs) {
for (let tab of tabs) {
// tab.url requires the `tabs` permission
console.log(tab.url);
}
}
function onError(error) {
console.log(`Error: ${error}`);
}
let querying = browser.tabs.query({url: "*://*.mozilla.org/*"});
querying.then(logTabs, onError);</pre>
<p>{{WebExtExamples}}</p>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{Compat("webextensions.api.tabs.query")}}</p>
<div class="note"><strong>Acknowledgements</strong>
<p>This API is based on Chromium's <a href="https://developer.chrome.com/extensions/tabs#method-query"><code>chrome.tabs</code></a> API. This documentation is derived from <a href="https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/api/tabs.json"><code>tabs.json</code></a> in the Chromium code.</p>
<p>Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.</p>
</div>
<div class="hidden">
<pre class="notranslate">// Copyright 2015 The Chromium Authors. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</pre>
</div>
|