I've been struggling for days on this, my extension's content script seems to be missing permissions or something, I've searched through the API docs and found nothing.
The messaging works if I send a message FROM the content page, but not TO the content page with the following code:
From the background page:
var messageCallback = function (e) {
var nodeMessage = JSON.parse(e.data);
switch (nodeMessage.ExecutionType) {
case 0:
chrome.tabs.create({ url: nodeMessage.Url }, function (tab) {
//injects injected.js NOT messages.js
injectCode(tab.id);
chrome.tabs.sendMessage(tab.id,nodeMessage);
});
break;
//some other switch cases...
From the content script:
chrome.runtime.onMessage.addListener(function (message) {
console.log('Message received');
var event = new CustomEvent("foo_receive", {
detail: message,
bubbles: true
});
console.log('Event sent');
document.dispatchEvent(event);
});
My manifest looks like this:
{
"manifest_version": 2,
"name": "extesnion_name",
"short_name": "thing",
"description": "long sentence",
"version": "1.0.0",
"icons": { "16": "icon16.png",
"48": "icon48.png",
"128": "icon128.png" },
"permissions": ["background", "tabs", "<all_urls>" ],
"background": {
"scripts": ["background.js"],
"persistent": true
},
"content_scripts":[
{
"matches": ["<all_urls>"],
"js": ["messages.js"],
}
],
"web_accessible_resources": ["injected.js"]
}
The following shows in the chrome console:
content script:
and background page: