I'm having a little trouble with this. I saw<a href="http://
groups.google.com/group/chromium-extensions/browse_thread/thread/
a1891daf44a94c1e/f4497d338bf298df?lnk=gst&q=sendrequest#"> this </
a>post but it is the other way around (content script -> background
page).
I am trying to get a script in the background page, store it in
localStorage and then pass the script to the content script where I
embed it in a page. Basically took the code from the google code
extensions page:
// background
var url = "http://www.website.com/script.js";
var x = new XMLHttpRequest;
x.onreadystatechange = function() {
if((x.readyState == 4) && (x.status == 200))
{
window.localStorage["SCRIPT"] = x.responseText;
}
};
x.open("GET", url, true);
x.send();
var script = window.localStorage["SCRIPT"];
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, {script: script}, function
(response) {});
});
// content script
var el = document.createElement("script");
el.setAttribute("type", "text/javascript");
el.setAttribute("id", this.scriptId);
var scriptText;
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
scriptText = request.script;
});
var textNode = document.createTextNode(scriptText);
el.appendChild(textNode);
document.body.appendChild(el);
The script gets appended to the document but is null. so it seems like
the message is not being passed properly. Any help would be greatly
appreciated!
--
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.