Reputation: 919
So, I have a chrome extension that does various things to a site. What I would like to do is rewrite it, to make it cleaner and more relevant, so I started. I have what content script, and it is 'infuse.js' which injects another file t3.js, into the website.
My question is - is there any way to pass data from localStorage to t3.js?
I have sendRequest and a response set up, so infuse.js can read the storage, but, if I try to do a sendRequest from t3.js, it obviously comes up as undefined as it isn't a content script, and thusly does not have access the API.
Let me know if you know anything.
Upvotes: 1
Views: 592
Reputation: 8542
There's something on this in the docs.... http://code.google.com/chrome/extensions/content_scripts.html#host-page-communication
Also, if you want to pass something to t3.js only once when its injected, then you can inject some js that sets some values, before injecting t3.js.
settings={1:"something'set'",2:["blek",1,2,3]}; //Youd get these from localStorage or something
head = document.getElementsByTagName('head')[0],
script = document.createElement('script');
script[script.innerText ? 'innerText' : 'textContent'] = 'var settings=' + JSON.stringify(settings)+ ';';
head.appendChild(script);
//Then inject t3.js
Upvotes: 2