I would like to create a package app chrome extension to allow the user to write and execute javascript code (like a javascript console).
I would like to use the eval() function to execute the JS code.
The classic javascript eval function throws an error when it’s called from a chrome extension:
Uncaught Error: Code generation from strings disallowed for this context
To use eval in a chrome extension people need to use a sandbox, but when I write the sandbox in the manifest I get this error:
There were warnings when trying to install this extension:
‘sandbox’ is not allowed for specified package type (theme, app, etc.).
UPDATE
According to this issue, sandboxes are not supported for package apps, so I have two questions:
-
Is there another method which I can use instead of
eval()? -
Is it possible to use
evalwithout a sandbox? (I think probably not for security reasons?)
UPDATE:
Since at least January 2013, Chrome now permits the
unsafe-evalContent Security Policy (CSP) directive, which allowsevalexecution outside of a sandbox:Add an appropriate CSP to you extension manifest, like:
The bug you refer to is now marked
fixed, and has been included since Chrome 22.Prior to the introduction of
'unsafe-eval', there was no way to have the CSP of amanifest_version: 2extension allow execution of arbitrary text as code. At the time, Google made it clear there was no way to remove this restriction (outside of sandboxing):As mentioned above, this restriction can now be relaxed.