In principle, this is possible. You should use the script content as a bridge between your newly created window and the script background. For example:
Your background script:
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { alert("message received"); }); chrome.windows.create({ type : 'popup', url : "http://yoursite.com/page.html", type: "popup" }, function(newWindow) { });
Your content script:
document.addEventListener("hello", function(data) { chrome.runtime.sendMessage("test"); })
page.html:
<script> var go = function() { var event = document.createEvent('Event'); event.initEvent('hello'); document.dispatchEvent(event); } </script> <a href="javascript:go();">Click me</a>
So, the idea is to send an event from a page using a document object. The content of the script listens for this event and once sends a message to the background image of the script where your code is originally.
Krasimir
source share