Reputation: 13
I want to create an exception for the chrome.tabs.query
status of my browser extension.
My code currently looks like this:
chrome.tabs.query({
"active": true,
"currentWindow": true,
"status": "loading", // <-- this line
"windowType": "normal"
}, ...);
But for www.gmx.net and www.web.de the status should be "complete"
. Can anyone tell me how am I able to create this exception?
Upvotes: 1
Views: 824
Reputation: 69336
You can add the url: []
property to the query information, like this:
chrome.tabs.query({
"active": true,
"currentWindow": true,
"status": "complete",
"windowType": "normal",
"url": ["*://www.gmx.net/*", "*://www.web.de/*"]
}, ...);
The above code will check for tabs that have completed loading, but only the ones that are either on gmx.net or web.de.
You can then combine the two queries and use the same function, like this:
function myFunction(tabs) {
if (~tab.url.indexOf('www.gmx.net') || ~tab.url.indexOf('www.web.de')) {
// the tab is on gmx.net or web.de and is complete
} else {
// the tab is not on gmx.net nor web.de and is still loading
}
};
chrome.tabs.query({
"active": true,
"currentWindow": true,
"status": "loading",
"windowType": "normal"
}, myFunction);
chrome.tabs.query({
"active": true,
"currentWindow": true,
"status": "complete",
"windowType": "normal",
"url": ["*://www.gmx.net/*", "*://www.web.de/*"]
}, myFunction);
Upvotes: 1