当我遍历当前窗口中的选项卡时,我使用chrome.tabs.executeScript
。我正在尝试从文件storeTabFavicon.js
中获取结果。
我读到回调函数每个选项卡上都有一个结果数组,但是它返回undefined
。例如,如果我打开了两个选项卡,则控制台将显示:
result[0]: null
result[0]: null
chrome.tabs.query({currentWindow: true}, function(tabs)
{
var tabFavicon= [];
var tabCount = 0;
for (; tabCount < tabs.length; tabCount++)
{
tabFavicon[tabCount] = storeTab(tabs, tabCount);
}
})
function storeTab(tabs, tabCount)
{
chrome.tabs.executeScript(tabs[tabCount].id, {file: "storeTabFavicon.js"}, function (result)
{
console.log("result[0]: " + result[0]);
})
}
var currentFaviconURL = document.querySelector("link[rel*='shortcut icon']").href;
if (currentFaviconURL)
{
return "yes";
}
else
{
return "no";
}
{
"manifest_version": 2,
"name": "Extension",
"version": "0.1",
"browser_action":
{
"default_popup": "popup.html"
},
"background":
{
"scripts": ["background.js"],
"persistent": false
},
"content_scripts":
[
{
"matches": ["<all_urls>"],
"js": ["content.js"]
}
],
"permissions": ["tabs", "storage", "*://*/*"],
}