Edit: I have been banned for asking this question, I'm not sure why or how to improve it — I think it's pretty specific and on topic. Help? Apparently it's a duplicate, so does that mean I should delete it? But I've read it's against the rules to delete? I really don't understand.
I have a Chrome extension with a background and content script. The content script sends url
to the background script fine, which talks to a .py script and creates new variable myPubscore
. I'm trying to send myPubscore
back to the content script.
The docs give an example where the background script sends {greeting:"farewell"}
to the content script, which works fine for me. But when I replace {greeting:"farewell"}
with {score: myPubscore}
, I get "undefined".
content.js
chrome.runtime.sendMessage({ "type": "articleUrl", "url": url }, function (response) {
console.log("here's the response for sending the URL");
console.log(response);
});
background.js
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.type == "articleUrl") {
console.log("background heard articleUrl")
console.log(request);
var articleUrl = request;
$.ajax({
type: 'POST',
url: `${url}/buttoncolor`,
data: articleUrl,
success: function urlFunction(data) {
var myPubscore = data;
console.log("myPubscore:")
console.log(myPubscore);
}
})
sendResponse({score: myPubscore});
}
...