My Requirement is whenever I click on the Extension Icon that should send a Request to content script and that should send reply with required properties. I am able to send the request. And when I check console Content script is recieving the request and processing it.But At popup side I could not receive anything.
Here is the request handler in Content script
chrome.extension.onRequest.addListener(function ListeningMethod(request, sender, callback)
{
switch(request.action)
{
case "QuestionProperties":
sendResponse({attributes: {"h":"s","r":"t"} });
break;
}
});
And on popup.html I am sending the request like this
$(document).ready(function(){
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, {action: "QuestionProperties"}, function(response){
alert('received something'); // Even this is not alerting
var data = JSON.parse(response.attributes);
alert(JSON.stringify(data)); // Here also I could not recieve anything. At Contentscript side I have checked the response that is being sent. I am able to see the data. But at Popup side I am unable to recieve it. Please help me on this.
});
});
});
Your
content_scriptisn’t calling the correct method to send the response. Your listener function is naming itcallbackbut then trying to usesendRequest. You should also either remove the function name or define it outside of the addListener for clarity.