I am working on a Chrome extension where I need to get a value from one part of the extension to the other. I have a background script the executes both scripts when the extension icon is clicked. One content script gets a value from the web page and needs to send it to external script. When the extension icon is clicked it executes the external script which listens for a message.
function message(){
console.log("Listening...");
var token = "";
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){
console.log("Attempting to get message...");
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
if (typeof request != 'undefined'){
console.log("Printing token...");
token = request.token;
console.log(token);
received = true;
sendResponse({greeting: "Got Token"});
}
});
}
message();
In the content script, when a button on the web page is clicked it should send a message to the external script. Here is the code in the content script.
chrome.runtime.sendMessage({token: token, URL: URL},function(response) {
console.log("Greeting 1");
console.log(response.greeting);
});
When I run the program I get the "Listening" printed out from the external script and I get the "Greeting 1" printed out from the content script. However, in the external script the listener doesn't seem to be working. I can breakpoint on it and step through the process but it just ends up skipping the block inside the listener and just ends at the end of the function doing nothing. Can anyone see what I might be doing wrong?
--
You received this message because you are subscribed to the Google Groups "Chromium-Extensions-Announce" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at https://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/f884b572-dea4-4e08-b8c9-1a1b33a05cd3%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.
☆PhistucK
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.