0

I am using below function to Get the current tab.

/**
 * Get the current tab.
 *
 * @param {function(tabObject)} callback - called when the URL of the current tab
 *   is found.
 */
function getCurrentTab(callback) {
// Query filter to be passed to browser.tabs.query - see
// https://developer.browser.com/extensions/tabs#method-query
var queryInfo = {
    active: true,
    currentWindow: true
};
browser.tabs.query(queryInfo, function (tabs) {
    if (browser.runtime.lastError) {
        // Something went wrong
        console.warn("Whoops.. " + browser.runtime.lastError.message);
        // TODO: Show error to the user
        return false;
    } else {


        // browser.tabs.query invokes the callback with a list of tabs that match the
        // query. When the popup is opened, there is certainly a window and at least
        // one tab, so we can safely assume that |tabs| is a non-empty array.
        // A window can only have one active tab at a time, so the array consists of
        // exactly one tab.
        var tab = tabs[0];

        // A tab is a plain object that provides information about the tab.
        // See https://developer.browser.com/extensions/tabs#type-Tab
        callback(tab);
    }
});

}

I am getting this warning Whoops.. Incorrect function.

Can someone help me with this and tell me what I am doing wrong?

Tarun
  • 1
  • Your code runs correctly in Edge 40.15063. Do you have 'tabs' permission in your manifest.json? – Anatoly Sazanov Jun 06 '17 at 07:49
  • Yes I have included both tabs as well as activeTab in permissions – Tarun Jun 06 '17 at 10:25
  • How about setting a breakpoint there and check if tabs/tabs[0] are defined? Maybe you can just ignore the error, or your callback is invalid, or there's more in error object. Also fiddling with queryInfo might help to detect what's broken. – Anatoly Sazanov Jun 06 '17 at 11:43
  • @AnatolySazanov I checked and tabs[0] is undefined – Tarun Jun 06 '17 at 11:53

0 Answers0