views:

46

answers:

1

I would like to create a Google Chrome extension that can fetch a remote javascript (via HTTPS) and execute it on a webpage (from within the extension sandbox). Basically, the script parses the page and generates data that I could then send back to my remote server.

The reason I want to do this is because I have a similar extension in Firefox, and I would like to unify the codebase as much as possible. I've already figured out how to do this in Firefox using a XmlHttpRequest and their evalInSandbox function.

Is this even possible in Chrome? It appears I can't use a XmlHttpRequest in Chrome, because it only allows XML or valid JSON (which excludes functions). I couldn't just insert a script tag on the page either, because then it wouldn't execute within the extension sandbox. Is there any way to do this?

A: 

What about converting your js code into a string, passing it through json or xml and then evaluating it using eval() (all security issues aside)?

serg