i am trying my hands at developing chrome extensions. i am trying to send a message to a content script from the background script. i have tried the following code:
manifest
{
....
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["http://myurl.com", "http://myurl.com"],
"js": ["content.js"],
"run_at": "document_end"
}
]
....
}
background script:
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
console.log("inside");
chrome.tabs.sendMessage(tabs[0].id, {greeting: "hello"}, function(response) {
console.log("Response");
});
});
content script:
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log("From Background Script: " + console.greeting);
return true;
});
i checked the console. the "inside" and "Response" are getting logged, but not the "From Background Script..."
what can be the problem?