I am trying to grab all tabs of the current window and loop through them.
currently using code:
chrome.tabs.query({currentWindow: true}, function(result) {
result.forEach(function(tab) {
do stuff here;
});
});
I have permissions for 'tabs' in the manifest.
It is throwing the error: "Error: Invocation of form tabs.query(object) doesn't match definition tabs.query(object queryInfo, function callback) at..."
I am confused as I clearly have the object and a callback function. I also see elsewhere that it can be done with a promise instead as:
var query = chrome.tabs.query({currentWindow: true});
query.then(function(tabs) {
tabs.forEach(function(tab) {
do stuff here;
});
});
But this throws the same error. Any ideas?
Promise-based approach is only valid in Firefox when using browser.* namespace instead of chrome.*
Chrome does not natively provide Promises for its API, though Mozilla has a polyfill if you prefer that.
Your first snippet is correct and will not throw this error. Make sure you check all invocations of tabs.query and properly reload the extension for your changes to apply.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With