Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome extension throwing error in console

My content script sends a message to background.js. In the callback handler for response, I had the last line as "alert(alrt_msg)". Upon executing code, I get the alert box, but after clicking "OK", the chrome console shows following in red:

Error in event handler for 'undefined': Cannot call method 'disconnect' of null TypeError: Cannot call method 'disconnect' of null
    at chromeHidden.Port.sendMessageImpl (miscellaneous_bindings:285:14)
    at chrome.Event.dispatch (event_bindings:237:41)
    at Object.chromeHidden.Port.dispatchOnMessage (miscellaneous_bindings:250:22) 

Its not much informative but intuitively I knew that this error is because some structure somewhere is garbage collected while user clicks on "OK". So I put my code as

window.setTimeout(function() { alert(alrt_msg); } , 1);

This made it work without above error. Still, after searching for documentation or google, I was not able to find the exact reason behind this. Can someone please explain whats going on and if documentation contains a specific way to do this?

like image 773
Methos Avatar asked Sep 19 '12 19:09

Methos


2 Answers

I have came to the same issue. This is due to an error (my code's fault) in a function which is called in the response handler.

Here is my code:

In background.js - the listening side

chrome.runtime.onMessage.addListener(
  function(request, sender, sendResponse) {
    var update_msg = 'test';
    sendResponse({data: update_msg});
    return false; // -> Add this or not add this do not matter
  });
}

On the sending side:

function updateObjDatabase(obj) {
  chrome.runtime.sendMessage({data: obj}, function(response) {
    // Update when it's done
    update_msg_handler(response.data);
  });
}

function update_msg_handler(msg) {
  ..... error code here
}

The wrong code is actually in the function update_msg_handler. But the Chrome console just won't tell you that details. You have to add some console.log to debug if you don't have an IDE.

like image 71
AGamePlayer Avatar answered Sep 23 '22 23:09

AGamePlayer


I had same error. It was iMacros app. After I deleted it no error.

like image 32
Aleksandr_A Avatar answered Sep 23 '22 23:09

Aleksandr_A