我有一个chrome扩展程序,当用户按下图标时,它将当前的tab.id
存储在变量中,然后在2分钟后运行chrome.tabs.executeScript
函数。据我所知,我的代码应该可以工作,但是出现以下错误: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)
修改选项卡的属性。
到目前为止,这是我的代码:
//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);
});
关于我的代码有什么问题的任何想法?我尝试过
tabId: activeTab
以及activeTab
,但是我一直遇到错误。如何为tabs.update
指定要更新的标签?谢谢。 最佳答案
你应该用
chrome.tabs.update(activeTab, {
active: true,
url: "https://mywebsite.com/" + myarray[count]
}, function(tab){});`
tabId
和updateProperties
是两个不同的参数。关于javascript - Chrome扩展程序-使用tabId更新某些标签,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38690052/