admin管理员组

文章数量:1301494

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?

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?

Share asked Aug 30, 2017 at 10:09 Stephen KeetonStephen Keeton 411 silver badge2 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 9

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.

本文标签: javascriptchrometabsquery(object) doesn39t match definitionStack Overflow