Google chrome extension chrome.tabs.getCurrent返回未定义
我正在尝试进行我的第一个扩展,它要求我获取当前选项卡的id。我已经在清单中设置为背景的脚本中获得了下面的代码。问题是它只返回未定义的。不知道下一步该怎么办。谢谢你的帮助Google chrome extension chrome.tabs.getCurrent返回未定义,google-chrome-extension,Google Chrome Extension,我正在尝试进行我的第一个扩展,它要求我获取当前选项卡的id。我已经在清单中设置为背景的脚本中获得了下面的代码。问题是它只返回未定义的。不知道下一步该怎么办。谢谢你的帮助 function oneFunction() { chrome.tabs.getCurrent(function(mytab){ console.log(mytab); }) } var t=setInterval(oneFunction,1000); 你应该使用 chrome
function oneFunction() {
chrome.tabs.getCurrent(function(mytab){
console.log(mytab);
})
}
var t=setInterval(oneFunction,1000);
你应该使用
chrome.tabs.query({active: true, currentWindow:true}, function(tabs)
{
});
还要知道,
tabs
是一个数组,包含与查询信息匹配的选项卡。在这种情况下,数组的长度为1,因此您必须将其用作选项卡[0]
请参阅文档:getCurrent用于其他用途。您需要查询({active:true,currentWindow:true},回调)