I would implement only one listener which responds according to the request.
The code should look like:
chrome.extension.onRequest.addListener(function(request, sender,
sendResponse){
if (request.name == "ur"){
sendResponse({domain: localStorage["url"]});
}else {
if (request.name="domain") {
sendResponse({domain: localStorage["domain"]});
}
}
});
Still, the 'one-listener-per-request' should work but the code above could
be used as a workaround until you figure out the problem.
Regards,
Yoanis.
On 12/27/09, FractalBob <[email protected]> wrote:
>
> My content script requests two strings from background.html:
>
> var subject = document.getElementById("subject");
> var body = document.getElementById("body");
>
> chrome.extension.sendRequest({name: "domain"},
> function(response)
> {
> subject.setAttribute("value", response.domain + ": ");
> });
>
> chrome.extension.sendRequest({name: "url"},
> function(response)
> {
> body.defaultValue = "URL of last page visited: " + response.url;
> });
>
> background.html earlier had saved the data to local storage:
>
> localStorage["domain"] = site;
> localStorage["url"] = tab.url;
>
> and waits for the requests from the content script:
>
> //Wait for request for the site value and URL from content script
> chrome.extension.onRequest.addListener(
> function(request, sender, sendResponse)
> {
> sendResponse({domain: localStorage["domain"]});
> });
>
> chrome.extension.onRequest.addListener(
> function(request, sender, sendResponse)
> {
> sendResponse({domain: localStorage["url"]});
> });
>
> For some reason, the content script receives the "domain" value OK,
> but displays "undefined" for the "url" value. TIA.
>
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Chromium-extensions" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<chromium-extensions%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/chromium-extensions?hl=en.
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Chromium-extensions" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/chromium-extensions?hl=en.