The SendMessage does not work on new Tab console.
The message does not arrive on the tab that was just opened.
Nothing is displayed on the console.
Below is all the files in the format I am using
Manisfest.json
{
"name": "SYSHP",
"version": "1.0",
"description" : "SYSHP",
"manifest_version": 2,
"permissions": [ "http://*/", "tabs", "activeTab", "notifications", "background" ],
"background": {
"scripts": [
"background.js"
]
},
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"content.js",
"lib/jquery.min.js"
],
"run_at": "document_end"
}
],
"icons": {
"128": "icon128.png",
"48": "icon48.png"
},
"browser_action": {
"default_icon": "icon128.png",
"default_title": "SYSHP",
"default_popup": "popup.html"
}
}
popup.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>SYSHP</title>
</head>
<body>
<button id="preparaLista">Preparar Lista</button>
<button>Download</button>
</body>
<script src="lib/jquery.min.js"></script>
<script src="popup.js"></script>
</html>
popup.js
var url = ('chrome-extension://' + chrome.i18n.getMessage('@@extension_id') + '/index.html');
document.getElementById("preparaLista").addEventListener("click",handleClick);
function handleClick(){
chrome.tabs.create({ url: url }, function(tab) {
chrome.tabs.sendMessage(tab.id, {type: "action_example"});
});
}
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>SYSHP</title>
</head>
<body>
</body>
<script src="lib/jquery.min.js"></script>
<script src="content.js"></script>
</html>
content.js
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
console.log("received message from popup: "+request.type);
});