I've just started looking into the world of Chrome extensions so
forgive me if this is question is a bit naive. I have a generic
utility JS file in the extension's directory, and I would like to
import that JS file into content scripts (not inject it into the DOM).
The only way I have been able to import that JS so far is via the
background page, I send a request to the background which in turn
loads the JS file using XMLHttpRequest, the response text is then sent
back to the content script which then pushing the text through eval()
Now, this is working fine but I'm concerned about overhead. I can
cache the JS text in the background script so it only needs to be
loaded once, but the eval() may be evil.
Is there any other way I can load the JS file into content scripts?
--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.
Thanks :-)
On Jan 29, 6:45 pm, Arne Roomann-Kurrik <kur...@chromium.org> wrote:
> Hi,
>
> The chrome.tabs.executeScript function might be what you're looking for:http://code.google.com/chrome/extensions/trunk/tabs.html#method-execu...
>
> Otherwise, you can just add the other JS file to your content_scripts
> section in your manifest - developers typically use that functionality to be
> able to use jquery (or some other library) in their content scripts. Check
> out a sample in the highlighted code here:http://code.google.com/chrome/extensions/trunk/content_scripts.html
>
> Hope this helps,
> ~Arne
>
>
>
> On Fri, Jan 29, 2010 at 1:01 AM, SiRobertson <nut...@gmail.com> wrote:
> > Hi guys,
>
> > I've just started looking into the world of Chrome extensions so
> > forgive me if this is question is a bit naive. I have a generic
> > utility JS file in the extension's directory, and I would like to
> > import that JS file into content scripts (not inject it into the DOM).
> > The only way I have been able to import that JS so far is via the
> > background page, I send a request to the background which in turn
> > loads the JS file using XMLHttpRequest, the response text is then sent
> > back to the content script which then pushing the text through eval()
>
> > Now, this is working fine but I'm concerned about overhead. I can
> > cache the JS text in the background script so it only needs to be
> > loaded once, but the eval() may be evil.
>
> > Is there any other way I can load the JS file into content scripts?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Chromium-extensions" group.
> > To post to this group, send email to chromium-extensi...@chromium.org.
> > To unsubscribe from this group, send email to
> > chromium-extensions+unsubscr...@chromium.org<chromium-extensions%2Bunsubscr...@chromium.org>
Otherwise, you can just add the other JS file to your content_scripts section in your manifest - developers typically use that functionality to be able to use jquery (or some other library) in their content scripts. Check out a sample in the highlighted code here: