[Vuejs]-Can't access chrome.extension.getBackgroundPage() when creating actual popup

0👍

The problem lay in a part of the code that I didn’t share, because I hadn’t thought it was relevant, and I was wrong.

Basically, I had two different chrome.runtime.sendMessage(message); on my content-script.js: one had an if statement on the receiver and the other did not. So every time I sent the request.stop message, the request.text was undefined and therefore caused window.text to become undefined.

Therefore, it worked on my browser-action popup, because there was no request.stop message sent, so window.text was still defined by the last message.

Once I added the second conditional statement, that would not run when the request.stop message was received.

window.text = "there is no text";

function receiver(request) {
if (request.stop == true){
  window.open("popup.html", "default_title", "width=375,height=600,titlebar=no,scrollbars=yes,resizable=no,top=0,left=0");
}

//removed this
//window.text = request.text;

//added this - if statement
if (request.text){
  window.text = request.text;
}
}

Leave a comment