I have a chrome extension that takes the URL from the active tab, finds another tab in the current window through tabs.query
, and will log something to console when found.
My question is, how to a get the tabId from the variable that stores the tabs.query?
//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');"
});
};
});
The chrome.tabs.executeScript(villageTab.tabId,
is clearly not the way to get the tabId of that object. Please tell me how to get the tabId so I can execute a script in that tab?