Hello! Help with the problem: I wanted to make a simple extension to chrome, this is almost full 0 :). I need to operate with the address bar, if it is more specific, then I need to redirect it to different domains by clicking on the links from the popup (some localization switch). So I added my script a trace of content to all the necessary pages:

var host1 = location.pathname; chrome.runtime.sendMessage({url: location.pathname}); 

in the main script trace:

 chrome.runtime.onMessage.addListener( function (request, sender, sendResponse) { var urls = request.url; }) document.addEventListener('DOMContentLoaded', function () { var links = document.getElementsByTagName("a"); for (var i = 0; i < links.length; i++) { (function () { var ln = links[i]; ln.onclick = function () { chrome.tabs.create({active: true, url: urls}); }; })(); } }) 

but in the place where the tab should be created - nothing happens. There is a hunch that the url itself comes later than onclics are formed, therefore they do not work. Tell me what am I doing wrong?

Thank!

  • Maybe it's in the scope of variables, and it simply is not visible outside of chrome.runtime.onMessage.addListener (). But not sure, he is not a super-specialist himself = (. - Dr. Mc My
  • What is, in your understanding, the "main script"? - Pavel Mayorov
  • Thanks for trying to help! The question is no longer relevant, everything is done. - Eugene

0