Using AngularJS in a Google Chrome extension

Deadly 提交于 2019-12-18 10:35:40

问题


I am trying to use the Google developer AngularJS library in an extension popup, but I get an error.

Error: Code generation from strings disallowed for this context at Function (unknown source) at Jb (chrome-extension://jambnlbfljcfpomlclcgphfmkjfiphkb/lib/angular.js:74:18) at k (chrome-extension://jambnlbfljcfpomlclcgphfmkjfiphkb/lib/angular.js:62:357) at Jc (chrome-extension://jambnlbfljcfpomlclcgphfmkjfiphkb/lib/angular.js:64:37) at Lc (chrome-extension://jambnlbfljcfpomlclcgphfmkjfiphkb/lib/angular.js:69:166) at chrome-extension://jambnlbfljcfpomlclcgphfmkjfiphkb/lib/angular.js:74:241 at chrome-extension://jambnlbfljcfpomlclcgphfmkjfiphkb/lib/angular.js:51:270 at F (chrome-extension://jambnlbfljcfpomlclcgphfmkjfiphkb/lib/angular.js:47:339) at X (chrome-extension://jambnlbfljcfpomlclcgphfmkjfiphkb/lib/angular.js:39:390) at t (chrome-extension://jambnlbfljcfpomlclcgphfmkjfiphkb/lib/angular.js:38:286)

What is the proper way to write the following content_security_policy directive for a Google Chrome plugin manifest file?:

"content_security_policy": "default-src 'self'; script-src 'unsafe-eval' 'unsafe-inline'; style-src 'unsafe-inline'",

currently it is throwing an error...


回答1:


You have to use CSP mode in angular to be inside Chrome extension. See: https://github.com/angular/angular.js/issues/893

Basically you have to declare your app as:

<html ng-app="" ng-csp>



回答2:


<html ng-app="" ng-csp> causes an error in Chrome stable M21 in a chrome-extension://*.xhtml file.

<html ng-app="" ng-csp=""> appears to work.



来源:https://stackoverflow.com/questions/11336969/using-angularjs-in-a-google-chrome-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!