Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google chrome extension chrome.tabs.getCurrent返回未定义_Google Chrome Extension - Fatal编程技术网

Google chrome extension chrome.tabs.getCurrent返回未定义

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

我正在尝试进行我的第一个扩展,它要求我获取当前选项卡的id。我已经在清单中设置为背景的脚本中获得了下面的代码。问题是它只返回未定义的。不知道下一步该怎么办。谢谢你的帮助

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},回调)