为什么browser.tabs.query在Edge Extension中不起作用?

时间:2017-06-06 06:21:40

标签: javascript microsoft-edge-extension

我正在使用以下功能获取当前标签。

/**
 * 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);
    }
});

}

我收到此警告哎呀..功能不正确。

有人可以帮助我并告诉我我做错了吗?

0 个答案:

没有答案