So on 2 pages I load scripts manifest

{ "manifest_version": 2, "name": "Empty", "version": "1.0", "icons": { "16": "images/empty_16.png", "32": "images/empty_32.png", "48": "images/empty_48.png", "64": "images/empty_64.png", "128": "images/empty_128.png" }, "permissions": [ "https://web.skype.com/*", "http://flparser/*" ], "content_scripts": [ { "matches": [ "https://web.skype.com/*" ], "js": ["content_scripts/webskype.js"] }, { "matches": [ "http://flparser/*" ], "js": ["content_scripts/flparser.js"] }] 

}

In one of them I hang events

 console.log("1"); chrome.runtime.onMessage.addListener(function(request, sender, callback) { debugger; console.log(arguments); }); 

in another, I'm trying to trigger an event

 var deleteLink = document.querySelectorAll(".bro-sendskype"); for (var i = 0; i < deleteLink.length; i++) { deleteLink[i].addEventListener('click', function(event) { debugger; chrome.runtime.sendMessage('start'); },false); } 

The code works exactly, that is, the handlers are hung and the message is sent, but it is not caught and does not write any errors to the console, what could be the problem? or mb there is an easier way to catch a house event from another tab

    1 answer 1

    It seems to have been achieved, but from the outside it seems as if a crutch of some kind of mb who will offer a better way. In the manifest we declare context javascripts on different pages on the legal page, the background will also be needed

      { "manifest_version": 2, "name": "Empty", "version": "1.0", "icons": { "16": "images/empty_16.png", "32": "images/empty_32.png", "48": "images/empty_48.png", "64": "images/empty_64.png", "128": "images/empty_128.png" }, "background": { "scripts": ["content_scripts/bg.js"] }, "permissions": [ "tabs" ], "content_scripts": [ { "matches": [ "https://web.skype.com/*" ], "js": ["content_scripts/webskype.js"] }, { "matches": [ "http://flparser/*" ], "js": ["content_scripts/flparser.js"] }] } 

    Further, from the page we need from which some action proceeds, we hang up a handler on any house

     deleteLink[i].addEventListener('click', function(event) {chrome.extension.sendRequest({ action: "brosend", login: broskype, message: text, }); }, false); 

    Now in backtragund, in fact, just a repeater which does nothing but accepts this request and sends 1 more request to all the tabs

     chrome.extension.onRequest.addListener(function(request) { chrome.tabs.query({}, function(tab) { console.log(1); tab.forEach((tab) => { chrome.tabs.sendMessage(tab.id, request); }); }); }); 

    Now in the context, the pages we are transmitting are processed so:

     chrome.runtime.onMessage.addListener(function(request) { console.log(1); if (request.action === "brosend") { console.log(request); } });