diff --git a/background.js b/background.js index 0ac6022..be3708b 100644 --- a/background.js +++ b/background.js @@ -20,9 +20,15 @@ chrome.extension.onConnect.addListener(function(port) { chrome.webRequest.onCompleted.addListener( function(details) { console.log(details); + var file; + if (details.url.indexOf("piwik.js") !== -1) { + file = "piwik.js"; + } else if (details.url.indexOf("action_name") !== -1) { + file = "piwik.php"; + } port.postMessage({ action: "requestResponse", - file: (details.url.indexOf("piwik.js") !== -1) ? "piwik.js" : "piwik.php", + file: file, data: details }); diff --git a/panel.js b/panel.js index 9bf4833..b2e4068 100644 --- a/panel.js +++ b/panel.js @@ -17,7 +17,7 @@ document.addEventListener('DOMContentLoaded', function() { if (message.action === 'injectResponse') { data.inject = message.data; // port.postMessage(message); - } else if (message.action === "requestResponse") { + } else if (message.action === "requestResponse" && message.file) { data.request[message.file] = message.data; } printData() @@ -26,10 +26,10 @@ document.addEventListener('DOMContentLoaded', function() { }()); - console.log(document.querySelector('#start')); document.querySelector('#start').addEventListener('click', function() { - chrome.extension.sendMessage({action: "inject", tabId: chrome.devtools.inspectedWindow.tabId}); - chrome.extension.sendMessage({action: "request", tabId: chrome.devtools.inspectedWindow.tabId}); + chrome.runtime.sendMessage({action: "inject", tabId: chrome.devtools.inspectedWindow.tabId}); + chrome.runtime.sendMessage({action: "request", tabId: chrome.devtools.inspectedWindow.tabId}); + // chrome.tabs.reload(chrome.devtools.inspectedWindow.tabId); console.log("sent message") }, false); });