1

I am trying to send a message from popup to background and get message back from background.

I get the message from popup and it prints Background received: Hi, but it doesn't print Popup received: Bye.

background.js

chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse) {
        console.log("Background received: " + request.msg);
        sendResponse({msg: "Bye"});
    }
)

popup.js

chrome.runtime.sendMessage({msg: "Hello"}, function(response) {
    console.log("Popup received: " + response.msg);
});

I've done this before, I'm sure, but I can't seem to find out what I'm doing wrong now. I must be overlooking something very simple. Thanks in advance!

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
Božo Stojković
  • 2,893
  • 1
  • 27
  • 52
  • 1
    I think have a look at this post will definitely help http://stackoverflow.com/questions/17103903/howto-send-a-message-from-content-script-to-inactive-popup-chrome-extension – CY_ Jun 13 '16 at 21:24
  • No need, everything works. I was just too tired and didn't look into popup's console. Thanks anyways! – Božo Stojković Jun 13 '16 at 21:25
  • Though, I could start using databases instead of sendMessage.. – Božo Stojković Jun 13 '16 at 21:28
  • 1
    Yeah, there are several options rather than just using sendMessage: https://groups.google.com/a/chromium.org/forum/#!topic/chromium-extensions/iFxhbJb_56c – CY_ Jun 13 '16 at 21:35

1 Answers1

0

I must be too tired.. I was staring hopelessly in the background page's console and didn't even think to look into popup console. Everything worked as expected from start. Oh dear..

Božo Stojković
  • 2,893
  • 1
  • 27
  • 52