"icons": { "128": "img/icon_128.png", }, "manifest_version": 2, "name": "external popup", "description": "test messaging between popup ,bg and cs", "permissions": [ "activeTab" ,"tabs"], "version": "2.0" }
I load my popup at runtime using below code in backgroundscript.js and it works fine
chrome.tabs.create({
url: chrome.extension.getURL('dialog.html'), focused: true }, function(tab) { console.log("popup launched"); });
my popup.html has below code:
<!DOCTYPE html>
<html>
<body style="width: 300px">
<button id="fetchevent">start reading events</button>
<button id="stopevent">stop reading events</button>
<button id="clickme">click me</button>
<script type="text/javascript" src="popup.js"></script>
</body>
</html>
My popup.js fetchevent button on click event then sends a message to background script requesting to send a message to active browser tab to start sending it the information of user events in the page.so that it can relay it back to popup html to populate. My popup.js was able to send the request to background script.
So the communication is popup request <-> backgroundscript request <-> content script -> sends messages continuosly to background script until stop request is received.
So when my background script receives the request from popup.html it tries to send a message to content script the following way. But it always gets popup.html when it queries chrome.tabs . And does because popup.html page is also open and thats the last active tab ?
Two questions here . How do i get current active chrome browser tab where this extension is loaded not the external popup html ? And is this right of way communicating between background script, content script and external popup ?
chrome.tabs.query({"active": true, "currentWindow": true}, function (tabs) {
tabURL = tabs[0].url;
console.log("URL from get-url.js", tabURL); // this always gets the popup.html not the browser tab url where extension is loaded
});