Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chrome.tabs.sendMessage : Error handling response

Im trying to send message to content.js from background.js when extension icon is clicked.

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();
})

I have this error in background.js, i don't know why.

Error handling response: TypeError: Error in invocation of
tabs.sendMessage(integer tabId, any message, optional object options,
optional function responseCallback): No matching signature.

What im doing wrong?

like image 525
bully Avatar asked Feb 05 '20 15:02

bully


1 Answers

In Background.js change the following :

chrome.tabs.sendMessage(CurrTab, 'run');

to

chrome.tabs.sendMessage(CurrTab.id, 'run');

As told by wOxxOm in the comments.

Secondly make sure that in manifest.json file you have specified the url of the website(where content script needs to be injected) in content_scripts/matches tag.

like image 174
neelesh bisht Avatar answered Dec 17 '22 13:12

neelesh bisht