aboutsummaryrefslogtreecommitdiff
path: root/files/ja/mozilla/add-ons/webextensions/api/tabs/query/index.html
blob: a70b2c9cf1896f7e376250d3da3846715648d61b (plain)
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
---
title: tabs.query()
slug: Mozilla/Add-ons/WebExtensions/API/tabs/query
translation_of: Mozilla/Add-ons/WebExtensions/API/tabs/query
---
<div>{{AddonSidebar()}}</div>

<p>指定されたプロパティを持つ全てのタブを取得します。何も指定しない場合、全てのタブを取得します。</p>

<p>この関数は <code><a href="/ja/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></code> を返す非同期関数です。</p>

<h2 id="構文">構文</h2>

<pre class="syntaxbox brush:js notranslate">var querying = browser.tabs.query(
  queryInfo             // object
)
</pre>

<h3 id="パラメータ">パラメータ</h3>

<dl>
 <dt><code>queryInfo</code></dt>
 <dd><code>object</code>. <code>query()</code> 関数はここで指定されたプロパティにマッチするタブだけを取得します。 このプロパティについての詳細は {{WebExtAPIRef("tabs.Tab")}} を参照してください。</dd>
 <dd>
 <dl class="reference-values">
  <dt><code>active</code>{{optional_inline}}</dt>
  <dd><code>boolean</code>. 各ウインドウの中でアクティブかどうか。</dd>
  <dt><code>audible</code>{{optional_inline}}</dt>
  <dd><code>boolean</code>. 音が鳴っているか。</dd>
  <dt><code>autoDiscardable</code>{{optional_inline}}</dt>
  <dd><code>boolean</code>. リソースが少なくなったときにブラウザーによって自動的にdiscardできるか。</dd>
  <dt><code>cookieStoreId</code> {{optional_inline}}</dt>
  <dd><code>string</code>. CookieストアのIDが <code>cookieStoreId</code> なタブのみを返すために使います。このオプションは <code>"cookies"</code> <a href="/ja/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions">permission</a>を持つ拡張でのみ使用できます。</dd>
  <dt><code>currentWindow</code>{{optional_inline}}</dt>
  <dd><code>boolean</code>. カレントウインドウの中のタブか。</dd>
  <dt><code>discarded</code>{{optional_inline}}</dt>
  <dd><code>boolean</code>. タブがdiscardされているか。 discardされたタブはコンテンツがメモリからアンロードされているが、タブの一覧には表示されたままになります。コンテンツはタブが次にアクティブになったときにリロードされます。</dd>
  <dt><code>highlighted</code>{{optional_inline}}</dt>
  <dd><code>boolean</code>. ハイライトされているか。</dd>
  <dt><code>index</code>{{optional_inline}}</dt>
  <dd><code>integer</code>. ウィンドウの中での位置。</dd>
  <dt><code>muted</code>{{optional_inline}}</dt>
  <dd><code>boolean</code>. ミュートされているか。</dd>
  <dt><code>lastFocusedWindow</code>{{optional_inline}}</dt>
  <dd><code>boolean</code>. 最後にフォーカスされたウインドウのタブか。</dd>
  <dt><code>openerTabId</code>{{optional_inline}}</dt>
  <dd><code>integer</code>. そのタブを開いたタブのID。</dd>
  <dt><code>pinned</code>{{optional_inline}}</dt>
  <dd><code>boolean</code>. ピン留めされているか。</dd>
  <dt><code>status</code>{{optional_inline}}</dt>
  <dd>{{WebExtAPIRef('tabs.TabStatus')}}. ロードが完了しているか。</dd>
  <dt><code>title</code>{{optional_inline}}</dt>
  <dd><code>string</code>. ページのタイトル。</dd>
  <dt><code>url</code>{{optional_inline}}</dt>
  <dd><code><code>string</code></code> もしくは <code><code>array</code> of <code><code>string</code></code></code>. 1つ以上の<a href="/ja/docs/Mozilla/Add-ons/WebExtensions/Match_patterns">マッチパターン</a>にマッチするタブか。フラグメント識別子にはマッチしません。</dd>
  <dt><code>windowId</code>{{optional_inline}}</dt>
  <dd><code>integer</code>. そのウインドウのID。カレントウインドウの場合は、 {{WebExtAPIRef('windows.WINDOW_ID_CURRENT')}} 。</dd>
  <dt><code>windowType</code>{{optional_inline}}</dt>
  <dd>{{WebExtAPIRef('tabs.WindowType')}}. そのタブの属するウインドウの種類。</dd>
 </dl>
 </dd>
</dl>

<h3 id="戻り値">戻り値</h3>

<p>マッチしたタブの情報を持つ <code>{{WebExtAPIRef('tabs.Tab')}}</code> オブジェクトの <code>array</code> に解決される <code><a href="/ja/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a></code></p>

<p>エラーが発生した場合、その Promise はエラーメッセージとともに却下されます。</p>

<h2 id="ブラウザ実装状況">ブラウザ実装状況</h2>

<p>{{Compat("webextensions.api.tabs.query", 10)}}</p>

<h2 id="例"></h2>

<p>全てのタブを取得する例:</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}`);
}

var querying = browser.tabs.query({});
querying.then(logTabs, onError);</pre>

<p>カレントウインドウの全てのタブを取得する例:</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}`);
}

var querying = browser.tabs.query({currentWindow: true});
querying.then(logTabs, onError);</pre>

<p>カレントウインドウのアクティブなタブを取得する例:</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}`);
}

var querying = browser.tabs.query({currentWindow: true, active: true});
querying.then(logTabs, onError);</pre>

<p>"mozilla.org" またはそのサブドメイン下のHTTP/HTTPS URLを開いている全てのタブを取得する例:</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}`);
}

var querying = browser.tabs.query({url: "*://*.mozilla.org/*"});
querying.then(logTabs, onError);</pre>

<p>moz-extension:// URLを開いている全てのタブを取得する例:</p>

<pre class="brush: js notranslate">function logTabs(tabs) {
  console.log(tabs);
  for (let tab of tabs) {
    // tab.url requires the `tabs` permission
    console.log(tab.url);
  }
}

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

var querying = browser.tabs.query({url: "moz-extension://*/*"});
querying.then(logTabs, onError);
</pre>

<p>この拡張機能のURLを開いている全てのタブを取得する例:</p>

<pre class="brush: js notranslate">function logTabs(tabs) {
  console.log(tabs);
  for (let tab of tabs) {
    // tab.url requires the `tabs` permission
    console.log(tab.url);
  }
}

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

var querying = browser.tabs.query({url: browser.extension.getURL("*")});
querying.then(logTabs, onError);
</pre>

<p>{{WebExtExamples}}</p>

<div class="note"><strong>Acknowledgements</strong>

<p>この API は Chromium の <a class="external external-icon" href="https://developer.chrome.com/extensions/tabs#method-duplicate"><code>chrome.tabs</code></a> APIに基づいています。 This documentation is derived from <a class="external external-icon" 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 での実装状況は Microsoft Corporation から提供されたものであり、ここでは 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>