我有一个Chrome扩展程序,它从活动标签中获取网址,在当前窗口中找到另一个标签tabs.query
,并在找到时将某些内容记录到控制台。
我的问题是,如何从存储tabs.query的变量中获取tabId?
//click button to trigger event
$('#geturlbutton').on('click', function(){
console.log('geturlbutton clicked')
//get current URL for for active tab
chrome.tabs.query({ currentWindow: true, active: true }, function (tabs) {
currentURL = tabs[0].url;
console.log(currentURL);
//find the tab with mywebsite
villageTab = chrome.tabs.query({url: "*://*.mywebsite.com/*"}, vilTab);
//once found run function to execute script in mywebsite tab
function vilTab(tabs){
chrome.tabs.executeScript(villageTab.tabId,{ <-- this is where error occurs
code: "console.log('executeScript worked');"
});
};
});
chrome.tabs.executeScript(villageTab.tabId,
显然不是获取该对象的tabId的方法。请告诉我如何获取tabId以便我可以在该选项卡中执行脚本?