1

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.

1 Answer 1

2

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 
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, I had forgotten I had asked this, and that was exactly what I had managed to come up with. I can't remember if I found it, or wrote it myself, but thanks for the quick answer!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.