Chrome 18 Dev/Canary has just been released, and content_security_policy
will be needed in the manifest for certain extensions.
I'm trying to get a CSP working for inline scripting, but I don't know if I'm doing something wrong or if this is a Chrome 18 bug.
manifest.json:
{
"name": "CSP Test",
"version": "1.0",
"manifest_version": 2,
"options_page": "test.html",
"content_security_policy": "default-src 'unsafe-inline'"
}
test.html:
<html><head>
<script type="text/javascript">
alert("hello");
</script>
</head></html>
In Chrome 18, this unpacked extension fails to load, displaying an error:
If I change 'unsafe-inline'
to 'self'
, the extension loads fine, but alert()
does not work, and the option page's console contains an error:
Refused to execute inline script because of Content-Security-Policy.
In Chrome 16, using 'unsafe-inline'
lets the extension load fine and alert()
works, too. However, in Chrome 16, replacing 'unsafe-inline'
with 'foo'
lets the extension load, but of course does not let alert()
work, so perhaps Chrome 18 is stricter than 16, but...
Is default-src 'unsafe-inline'
actually invalid, or is this a bug? What CSP value can I use to make alert()
work in Chrome 18?
Based on the accepted answer below, inline scripts no longer work in extensions in Chrome 18. alert()
will need to be placed in its own JavaScript file.