Hello.
Question:

  1. main: how to send a message to the specified tab, not by its id, but being attached to the url.
  2. required decoding of parameters of the method tabs.query() ;

     chrome.tabs.query( { active: true, currentWindow: true }, function(tabs) { chrome.tabs.sendMessage( tabs[0].id, { greeting: "hello" }, function(response) { console.log(response.farewell); } ); } ); 
  • which means "decoding of the parameters of the method of tabs.query ();" is required ? - UserName
  • I need to: 1. send a message to the specified tab, not by its id, but being attached to the url. 2. understanding: what are the parameters of the method tabs.query (); and what they mean = help in this task. - Max

1 answer 1

You can send messages to tabs only by their id .

In this case, you can get a list of tabs with a specific url , then go through them, determining whether to send a message or not.

For this, we form the corresponding queryInfo object (the first parameter):

 chrome.tabs.query({url: "http://www.example.com/*"}, function (tabs) { if (tabs.length != 0) { for (var i = 0; i < tabs.length; i++) { // Определить условие можно, или сразу всем слать chrome.tabs.sendMessage(tabs[i], {greeting: "hello"}); } } }); 

Get all the packages with the specified url in the current window.

I note that you can send as one url and an array with url

Go through them and send messages by specifying their id.

The full list of parameters for the query function is presented here.

UPD : about "permission": ["tabs"]; do not forget.

  • Comments are not intended for extended discussion; conversation moved to chat . - Nick Volynkin