vendredi 8 septembre 2017

undefined variable through oundefined

I'm currently building a chrome extension and there occurred some error when I tried to pass a variable from a content_script file to popup file.

So, in the content_script file, I have an array course, and it's sent by an onMessage listener.

chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
    if(message === "courses"){
        sendResponse(courses);
    }
});

And in the popup file, it receives the variable through a parameter.

chrome.runtime.sendMessage('courses', function(response){
alert(response)});

And dialogue prints undefined. I've already seperately tested the variable in the first file, which has a value.

Aucun commentaire:

Enregistrer un commentaire