Recently I had problem how to use sendMessage and I have successfully managed it that I could send and recieve messages on both ends. But I had to remake it a bit to use namespace and now I have this strange error.
I just upgraded from 48.0b6 to 48.0b7.
I have been using callback too.
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
SIDE NOTE: I constant problems with the Addon debugger that it does not show current content of file I am debugging and that it shows and prints incorrect errors because it does not see the current version of the file.
So the error,
sendmessage error:Error: Could not establish connection. Receiving end does not exist
probably happened when I added a callback.
When I removed it and HAD TO RESTART FIREFOX and Addon Debugger to see the current version. So the bellow code does not print error because it does not have the callback function:
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
MyNamespace.sendCommandMessage = function(command, namespace){
chrome.tabs.query(
{
active: true,
currentWindow: true // send it to the active window
},
function(tabs) {
chrome.tabs.sendMessage(
tabs[0].id,
command/*, // message
{}, // options optional object
function(response) {
if (chrome.runtime.lastError) {
console.log("error:" + chrome.runtime.lastError);
console.log(chrome.runtime.lastError);
}
else
{
console.log("message successfully sent");
}
} // optional function
*/
)
} // end of query() callback
); // end of query() call
}
This is used like this, when shif+ctrl+u is pressed:
MyNamespace.sendCommandMessage(command);
Now, the current code.
MyNamespace.sendCommandMessage = function(command){
chrome.tabs.query(
{
active: true,
currentWindow: true // send it to the active window
},
function(tabs) {
chrome.tabs.sendMessage(
tabs[0].id,
command,
// {}, // options optional object
function(response) {
if (chrome.runtime.lastError) {
console.log("error:" + chrome.runtime.lastError);
console.log(chrome.runtime.lastError);
}
else
{
console.log("message successfully sent");
}
} // optional function
)
} // end of query() callback
); // end of query() call
Prints the error above.
I tried to pass the empty object as options parameter and that cause the same problems.
So I need to ask you how this should be correctly done. Or what is the reason of the error. Do you also have the similar problems with the Addon Debugger? I still need to restart it because I don’t see the current version of the file. So I quite cannot rely on what the Addon Debugger shows!