0

I have a requirement like when I click some button in the page.html which will trigger an event, that event should be captured in contentscript and sent to background.js and devtools.js for processing. I can ble to get the message passed from contectscript in background.js , but fails to send the message to devtools.js.

contentscript.js

document.addEventListener("hello", function(data) {
    var button = document.getElementById("mybutton");
    console.log("Value: "+button.value);
    chrome.runtime.sendMessage(button.value);
})

background.js

chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
    var mes="message received: " + message;

   var port = chrome.extension.connect({
   name: "Sample Communication" //Given a Name
   });
   port.postMessage("Request Tab Data");

   alert(mes);
});

devtools.js

var ResultShow;
chrome.devtools.panels.create("GetNetWorkData",
                              "Network.png",
                              "panel.html",
                              function(panel) {
panel.onShown.addListener(function(panelWindow) {
    chrome.devtools.network.getHAR(
                     function(harLog) {
            //  alert('came here1: '+harLog.entries.length);
                       window.DataResults=harLog;
                alert('Total Logs: '+ window.DataResults.entries.length);
                                  });   
                 for (i = 0; i < window.DataResults.entries.length; i++)
                 {
                     window.ResultShow =window.ResultShow+' ; Time :'+window.DataResults.entries[i].time +'Start DateTime :'+window.DataResults.entries[i].startedDateTime;
                 }
    panelWindow.document.body.appendChild(document.createTextNode(window.ResultShow));
    });

    });

    chrome.extension.onConnect.addListener(function (port) {
    port.onMessage.addListener(function (message) {
    alert("DT"+message);
            });
        });                            

In devtools,trying to create a panel, based on the message I get from background.js

rajesh A
  • 373
  • 4
  • 10
  • I don't know devtools, but to connect from a background script to a content script, you need [`chrome.tabs.connect`](https://developer.chrome.com/extensions/tabs#method-connect). Could that be your problem? – Teepeemm Oct 23 '15 at 15:15
  • Nope , just to simplify, how can a pass a message from either contentscript or background js to devtools, I need this communication. @Teepeemm – rajesh A Oct 26 '15 at 07:24
  • Answer in the following link helped me to achieve my requirement http://stackoverflow.com/questions/11661613/chrome-devpanel-extension-communicating-with-background-page][1] – rajesh A Oct 26 '15 at 10:59

0 Answers0