0

I have a page which sends a message to the background script. The content of the message is nothing much, just an array of information it wants to receive in return.

chrome.runtime.sendMessage(initRequest, Init);

function Init(message){
    console.log(message);
    console.log(chrome.runtime.lastError);

    if (message.init == false)
    ...

My background.js takes that and processes it.

chrome.runtime.onMessage.addListener(
  async (message, sender, Reply) => {
    //  Stuff happens here...
    console.log(response);
    Reply(response);
  }
);

My log shows that everything is being processed as required to come out of the other end. Right after I get the response exported to the console, my page runs Init() and that's where I lose track of what's going on.

undefined

{message: 'The message port closed before a response was received.'}

Error handling response: TypeError: Cannot read properties of undefined (reading 'init') at Init

This was an external page that I realised should just get rolled into the main extension. It used to work. I tossed in some console.log(...) lines to see if I could follow the execution, but I'm stumped; the code running in the background needs time to run (it queries a server) and Init() waits until the moment it finishes, so I feel like the issue is with Init() not being given the response data, but I can't work out why...

AnthonyHJ
  • 11
  • 3

0 Answers0