Katie Katie - 4 months ago 34
Javascript Question

Chrome extension - update certain tab using tabId

I have a chrome extension that when a user presses the icon it stores the current

tab.id
in a variable, and then after 2 minutes runs a
chrome.tabs.executeScript
function. As far as I can tell, my code should work but I get an error of:

Uncaught Error: Invalid value for argument 1. Property 'tabId': Unexpected property


From the chrome developer site


Update

chrome.tabs.update(integer tabId, object updateProperties, function callback)


Modifies the properties of a tab.


Here is my code so far:

//Up here is the logic for handling the icon press
chrome.tabs.query({ active: true, currentWindow: true }, function(arrayOfTabs) {

var activeTab = arrayOfTabs[0].id; //this is the active tab id.

setInterval(function() { //Interval for every 2 minutes
chrome.tabs.update({
tabId: activeTab, //this is where I get an error... What's wrong with this?
active: true,
url: "https://mywebsite.com/" + myarray[count]
}, function(tab) {
chrome.tabs.executeScript(tab.id, {
file: "function/jquery.min.js",
runAt: "document_end"
});

chrome.tabs.executeScript(tab.id, {
file: "function/code.js",
runAt: "document_end"
});

})
count++;
}, timer);
});


Any ideas on what's wrong with my code? I have tried
tabId: activeTab
as well as just
activeTab
but I keep getting an error. How can I specify to the
tabs.update
which tab I want to update? Thank you.

Answer

You should use

chrome.tabs.update(activeTab, {
  active: true,
  url: "https://mywebsite.com/" + myarray[count]
}, function(tab){});`

tabId and updateProperties are two different parameters.