因此,我正在开发一个Chrome扩展来定期重新加载页面,但我发现了一个错误:Error handling response: TypeError: Error in invocation of pageAction.show(integer tabId, optional function callback): No matching signature.
。
manifest.json:
{
"name": "Reloader",
"version": "1.0.0",
"description": "Reloads pages.",
"permissions": ["tabs", "declarativeContent", "storage"],
"background": {
"scripts": ["background.js"],
"persistent": false
},
"page_action": {
"default_popup": "popup.html",
"default_icon": {
"16": "images/symbolsmall.png"
}
},
"manifest_version": 2
}
background.js:
chrome.tabs.onActivated.addListener(function(tabs) {
chrome.pageAction.show(tabs.id);
});
我执行了一些console.logs,并检查了文档中的chrome.pageAction.show和语法检查,但错误仍然存在。任何帮助都将不胜感激。
发布于 2019-07-24 22:56:39
该错误消息表示您传递了不正确的参数。如果您在devtools for the background page中调试代码,您将看到tabs.id
is undefined
。正如您在documentation中所看到的,onActivated的侦听器接收一个内部包含tabId
和windowId
的对象:
chrome.tabs.onActivated.addListener(function(activeInfo) {
chrome.pageAction.show(activeInfo.tabId);
});
请注意,如果您计划像现在一样无条件地显示page_action,那么使用page_action根本没有任何好处,您可以简单地切换到默认启用的browser_action,这样您就不需要使用show()了。
发布于 2020-07-20 21:18:51
当您在回调参数中调用函数而不是传递它时,也会发生此错误。
function foo(param){
//do something
}
chrome.tabs.onActivated.addListener(foo(param)); //this will give you the error
chrome.tabs.onActivated.addListener(foo); //this should work fine
看起来很明显,但是,我已经犯过无数次这个错误了。希望对您有所帮助。
https://stackoverflow.com/questions/57183361
复制相似问题