Katie Katie - 1 year ago 118
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

in a variable, and then after 2 minutes runs a
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


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
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"

}, timer);

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

Answer Source

You should use

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

tabId and updateProperties are two different parameters.