So I have popup page index.html:
Code:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function zadost() {
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, {action: "getHtml"}, function(response) {
console.log(response.html);
if (response.html) {
document.getElementById('output').innerHTML = response.html;
} else {
document.getElementById('output').innerHTML = 'I did not get the source code.';
}
});
});
}
</script>
</head>
<body onLoad="zadost()">
<h1>KatastrBuster</h1>
<div id="output"></div>
</body>
</html>
Content script script.js:
Code:
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if (request.action == "getHTML") {
console.log("Got getHTML request.").
var htmlCode = document.documentElement.outerHTML;
sendResponse({html: htmlCode});
} else {
sendResponse({});
}
});
and manifest.json:
Code:
{
"name": "KatastrBuster",
"version": "0.1",
"description": "Some kiddings about the extension.",
"browser_action": {
"default_icon": "ikonka.png",
"default_title": "KatastrBuster",
"default_popup": "index.html"
},
"content_scripts": [
{
"matches": ["http://*/*"],
"js": ["script.js"]
}
],
"permissions": [ "tabs", "http://*/*" ]
}
That should send a request from Popup to content script for HTML code. After, content script should get the source code and resend it to the popup to show the code, but nothing hapend.
Console is empty all the time and no code is visible. Could you tell me, where is the problem?