2017-07-06 14:35:58 +02:00
|
|
|
// Chrome automatically creates a background.html page for this to execute.
|
|
|
|
// This can access the inspected page via executeScript
|
|
|
|
//
|
|
|
|
// Can use:
|
|
|
|
// chrome.tabs.*
|
|
|
|
// chrome.extension.*
|
|
|
|
|
|
|
|
chrome.extension.onConnect.addListener(function(port) {
|
|
|
|
|
|
|
|
function extensionListener(message, sender, sendResponse) {
|
|
|
|
if (message.tabId) {
|
|
|
|
if (message.action === 'inject') {
|
|
|
|
//Evaluate script in inspectedPage
|
|
|
|
chrome.tabs.executeScript(message.tabId, {file: "inject.js"}, function(result) {
|
2017-07-06 16:50:41 +02:00
|
|
|
port.postMessage({action: "injectResponse", data: result[0]});
|
2017-07-06 14:35:58 +02:00
|
|
|
});
|
2017-07-06 16:50:41 +02:00
|
|
|
console.log("inject")
|
2017-07-06 14:35:58 +02:00
|
|
|
} else if (message.action === "request") {
|
2017-07-06 16:50:41 +02:00
|
|
|
console.log("request");
|
2017-07-06 14:35:58 +02:00
|
|
|
chrome.webRequest.onCompleted.addListener(
|
|
|
|
function(details) {
|
|
|
|
console.log(details);
|
2017-07-06 16:50:41 +02:00
|
|
|
port.postMessage({
|
|
|
|
action: "requestResponse",
|
|
|
|
file: (details.url.indexOf("piwik.js") !== -1) ? "piwik.js" : "piwik.php",
|
|
|
|
data: details
|
|
|
|
});
|
|
|
|
|
2017-07-06 14:35:58 +02:00
|
|
|
},
|
|
|
|
{urls: ["*://*/piwik.js", "*://*/piwik.php*"], tabId: message.tabId} // only look for request in open tab
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This accepts messages from the inspectedPage and
|
|
|
|
// sends them to the panel
|
|
|
|
} else {
|
|
|
|
port.postMessage(message);
|
|
|
|
}
|
|
|
|
sendResponse(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Listens to messages sent from the panel
|
|
|
|
chrome.extension.onMessage.addListener(extensionListener);
|
|
|
|
console.log("connected to extention");
|
|
|
|
|
|
|
|
port.onDisconnect.addListener(function(port) {
|
|
|
|
chrome.extension.onMessage.removeListener(extensionListener);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
|
|
|
|
return true;
|
|
|
|
});
|
|
|
|
|