i am using the following codes to send a variable/message from the popup toolbar to the content scripts. however, i am not able to retrieve anything from the content scripts. When i send 'asdf' over to the content scripts, i am able to see 'undefined' found in the console. Please help, i have tried to follow a chrome extension answer but nothing seems to work. I am working with firefox webextension instead of chrome extension.
manifest.json
{
"manifest_version": 2,
"name" : "FPV",
"version" : "1.0",
"content_scripts":[
{
"matches": ["http://www.*.com/*","https://www.*.com/*"],
"js": ["jquery-3.1.1.min.js","CalculatePost.js"]
}
],
"permissions": [
"activeTab"
],
"browser_action": {
"browser_style" : true,
"default_icon": "icons/border-48.png",
"default_title": "FPV",
"default_popup": "popup/Toolbar.html"
},
"background":{
"scripts" : ["background.js"]
}}
popup (Toolbar.html)
<html>
<head>
<link rel="stylesheet" href="Toolbar.css"/>
<script src="Toolbar.js"></script>
</head>
<body>
<div> <input type="text" id="AccessToken" placeholder="Access Token" ></input> </div>
<div class="button CalculatePost"> RUN </div>
</body>
</html>
popup js (Toolbar.js)
if (e.target.classList.contains("CalculatePost")) { //function to refresh page
//var AccessToken = document.getElementById('AccessToken').value;
browser.tabs.executeScript(null, {
file: "/CalculatePost.js"
}, function(){
//browser.tabs.sendMessage(null, AccessToken);
//trying to pass a data from html to the content scripts
browser.tabs.sendMessage(null, 'test');
});
}}
content scripts (CalculatePost.js)
var received;
browser.runtime.onMessage.addListener(function(message, sender, sendResponse) {
received = message;
});
console.log(received);