Javascript 为什么browser.tabs.query在“边缘扩展”中不工作?
我正在使用下面的函数获取当前选项卡Javascript 为什么browser.tabs.query在“边缘扩展”中不工作?,javascript,microsoft-edge-extension,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
/**
* 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);
}
});
}
我收到了这个警告哎呀。。功能不正确
有人能帮我解决这个问题并告诉我我做错了什么吗?您的代码在Edge 40.15063中正确运行。您在manifest.json中是否具有“tabs”权限?是的,我已在permissionsHow中包括了这两个选项卡以及activeTab关于在那里设置断点的内容,并检查是否定义了选项卡/选项卡[0]?也许您可以忽略错误,或者您的回调无效,或者错误对象中有更多错误。另外,摆弄queryInfo可能有助于检测哪些内容被破坏了。@AnatolySazanov我检查了,选项卡[0]未定义