AngularJS 在 chrome 扩展中使用 eval [英] AngularJS uses eval in chrome extension

查看:41
本文介绍了AngularJS 在 chrome 扩展中使用 eval的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最新的 AngularJS (1.3 beta 19) 使用 eval.这在 chrome extionion 中是被禁止的.

The lates AngularJS (1.3 beta 19) uses eval. This is prohibited in chrome extionsion.

如何解决问题不允许 evals?

How to fix the issue without allowing evals?

错误信息:

拒绝将字符串作为 JavaScript 求值,因为 'unsafe-eval' 是以下内容安全中不允许的脚本来源政策指令:script-src 'self' chrome-extension-resource:".

Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:".

堆栈跟踪:

angular.js:1011
csp angular.js:1011
(anonymous function) angular.js:23556

更新:查看ng-csp文档https://docs.angularjs.org/api/ng/directive/ngCsp

过时:看起来 AngularJS 无法检测到 chrome 扩展中的 CSP.使用显式 ng-csp.AngularJS 问题的链接:https://github.com/angular/angular.js/issues/8777

OUTDATED: It looks like AngularJS fails to detect CSP in chrome extension. Use explicit ng-csp. Link to the AngularJS issue: https://github.com/angular/angular.js/issues/8777

推荐答案

引用文档 那个德米特里链接:

To quote documentation that Dmitry linked:

Angular 尝试自动检测 CSP 是否处于活动状态并自动打开CSP 安全模式.但是,此自动检测会触发 CSP 错误以登录控制台:

Angular tries to autodetect if CSP is active and automatically turn on the CSP-safe mode. This autodetection however triggers a CSP error to be logged in the console:

拒绝将字符串作为 JavaScript 求值,因为 'unsafe-eval' 是以下内容安全中不允许的脚本来源策略指令:default-src 'self'".请注意,'script-src' 不是显式设置,因此default-src"用作后备.

这个错误无害但很烦人.为了防止错误显示向上,将 ngCsp 指令放在根元素上申请的或在 angular.js 脚本标签上,以 html 中最先出现的为准文档.

This error is harmless but annoying. To prevent the error from showing up, put the ngCsp directive on the root element of the application or on the angular.js script tag, whichever appears first in the html document.

这篇关于AngularJS 在 chrome 扩展中使用 eval的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆