javascript - Chrome Extensions Content-Security-Policy -
javascript - Chrome Extensions Content-Security-Policy -
i have need in extension dynamically load code . wrote load -
var se = document.createelement('script'); se.setattribute('type', 'text/javascript'); se.appendchild(document.createtextnode(code)); document.getelementsbytagname('head').item(0).appendchild(se);
and security policy in manifest.js -
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
this throws javascript error -
"refused execute inline script because violates next content security policy directive: "script-src 'self' 'unsafe eval'"
my question - why isn't relaxed ? added line in manifest allow unsafe evals .
i don't think it's utilize of eval
causing error. appears you're violating policy against executing inline javascript, injecting <script>
blocks head
of document.
according documentation on content security policy:
inline javascript not executed. restriction bans both inline blocks , inline event handlers (e.g. < button onclick='...'>).
also note:
inline script
there no mechanism relaxing restriction against executing inline javascript. in particular, setting script policy includes 'unsafe-inline' have no effect.
instead of placing code inline you'll have come approach utilizes external js
files accomplish whatever trying do.
javascript html5 google-chrome google-chrome-extension content-security-policy
Comments
Post a Comment