我试图content.js
从background.js
单击扩展图标时发送消息到。
Background.js
:
chrome.browserAction.onClicked.addListener(function(){
chrome.tabs.query({active : true, lastFocusedWindow : true}, function (tabs) {
var CurrTab = tabs[0];
chrome.tabs.sendMessage(CurrTab, 'run');
})
})
Content.js
:
chrome.runtime.onMessage.addListener(function(){
view();
})
我在中有此错误background.js
,我不知道为什么。
Error handling response: TypeError: Error in invocation of
tabs.sendMessage(integer tabId, any message, optional object options,
optional function responseCallback): No matching signature.
我在做什么错?
在Background.js中,更改以下内容:
chrome.tabs.sendMessage(CurrTab, 'run');
至
chrome.tabs.sendMessage(CurrTab.id, 'run');
正如wOxxOm在评论中所说。
其次,请确保在manifest.json文件中,您已在content_scripts / matches标签中指定了网站的网址(需要在其中插入内容脚本)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句