noobie JS dev here, I am developing a chrome extension and I have 2 scripts, background.js and popup.js - I need to call a function in popup.js based on some action in background.js, so I found I can send a message. This works fine for me, but I also need to send reponse back to the background.js script and I get this error at popup.html:1

Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.

Funny thing is, console from inspect view: background @chrome://extensions/ logs the response fine, but console from inspecting the popup logs undefined and shows the error.

Thank you for any help.

(the code below is simplified)

background.js:

    chrome.runtime.sendMessage('hi', response => {
      console.log(response);
    });

popup.js

chrome.runtime.onMessage.addListener(
    function (message, sender, sendResponse) {
        if (message == 'hi') {
            //some DOM actions here
            sendResponse('bye');
        }
        return true;
    });

1 Answers

0
Dejw On

Just deleted return true as @wOxxOm suggested.