When I am send a message from google chrome extension v3 popup to the background. shows error:
Unchecked runtime.lastError: The message port closed before a response was received.
this is my popup.js send code:
chrome.runtime.sendMessage({greeting: "Hello"},function(response){
alert(response);
});
this is the background.js receive code:
chrome.runtime.onMessage.addListener(function (request,sender,sendResponse){
if( request.greeting === "Hello" )
{
var tabURL = "Not set yet";
debugger;
chrome.tabs.query({active:true},function(tabs){
if(tabs.length === 0) {
sendResponse({});
return;
}
// tabURL = tabs[0].url;
sendResponse( {navURL:tabURL} );
});
}
});
I have debugging the code and found the background will send a response to the popup, why still get this error? something I am missing?