--- title: tabs.query() slug: Mozilla/Add-ons/WebExtensions/API/tabs/query translation_of: Mozilla/Add-ons/WebExtensions/API/tabs/query ---
指定されたプロパティを持つ全てのタブを取得します。何も指定しない場合、全てのタブを取得します。
この関数は Promise を返す非同期関数です。
var querying = browser.tabs.query( queryInfo // object )
queryInfoobject. query() 関数はここで指定されたプロパティにマッチするタブだけを取得します。 このプロパティについての詳細は {{WebExtAPIRef("tabs.Tab")}} を参照してください。active{{optional_inline}}boolean. 各ウインドウの中でアクティブかどうか。audible{{optional_inline}}boolean. 音が鳴っているか。autoDiscardable{{optional_inline}}boolean. リソースが少なくなったときにブラウザーによって自動的にdiscardできるか。cookieStoreId {{optional_inline}}string. CookieストアのIDが cookieStoreId なタブのみを返すために使います。このオプションは "cookies" permissionを持つ拡張でのみ使用できます。currentWindow{{optional_inline}}boolean. カレントウインドウの中のタブか。discarded{{optional_inline}}boolean. タブがdiscardされているか。 discardされたタブはコンテンツがメモリからアンロードされているが、タブの一覧には表示されたままになります。コンテンツはタブが次にアクティブになったときにリロードされます。highlighted{{optional_inline}}boolean. ハイライトされているか。index{{optional_inline}}integer. ウィンドウの中での位置。muted{{optional_inline}}boolean. ミュートされているか。lastFocusedWindow{{optional_inline}}boolean. 最後にフォーカスされたウインドウのタブか。openerTabId{{optional_inline}}integer. そのタブを開いたタブのID。pinned{{optional_inline}}boolean. ピン留めされているか。status{{optional_inline}}title{{optional_inline}}string. ページのタイトル。url{{optional_inline}}string もしくは array of string. 1つ以上のマッチパターンにマッチするタブか。フラグメント識別子にはマッチしません。windowId{{optional_inline}}integer. そのウインドウのID。カレントウインドウの場合は、 {{WebExtAPIRef('windows.WINDOW_ID_CURRENT')}} 。windowType{{optional_inline}}マッチしたタブの情報を持つ {{WebExtAPIRef('tabs.Tab')}} オブジェクトの array に解決される Promise。
エラーが発生した場合、その Promise はエラーメッセージとともに却下されます。
{{Compat("webextensions.api.tabs.query", 10)}}
全てのタブを取得する例:
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);
カレントウインドウの全てのタブを取得する例:
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);
カレントウインドウのアクティブなタブを取得する例:
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);
"mozilla.org" またはそのサブドメイン下のHTTP/HTTPS URLを開いている全てのタブを取得する例:
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);
moz-extension:// URLを開いている全てのタブを取得する例:
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);
この拡張機能のURLを開いている全てのタブを取得する例:
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);
{{WebExtExamples}}
この API は Chromium の chrome.tabs APIに基づいています。 This documentation is derived from tabs.json in the Chromium code.
Microsoft Edge での実装状況は Microsoft Corporation から提供されたものであり、ここでは Creative Commons Attribution 3.0 United States License に従っています。
// 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.