I am trying to send a variable from a file called popup.js to another called content.js.
I've tried using localStorage, but the content.js file receives it as null (I am certain that the popup.js file declares it as string because I output its type from the popup to the console). Now, I am using chrome.runtime to send the variable to the content.js, but what I'm trying now is not giving me anything, not even any errors.
This is my popup.js:
$(function(){
$('#submit').click(function(){
var amount = $('#repitions').val();
if (amount){
var x = JSON.stringify(amount);
chrome.runtime.sendMessage({y: x});
}
});
});
And this is the section of the content.js file that receives the message:
chrome.runtime.onMessage.addListener(function(request){
z = request;
alert(z);
});
There is something I'm doing wrong?. Thank you for reading my question.