javascript - 在 Chrome 扩展中使用 React js

标签 javascript google-chrome google-chrome-extension reactjs babeljs

我正在按照本教程构建一个新的选项卡 chrome 扩展.. https://facebook.github.io/react/docs/tutorial.html

但是当我附上

<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>

按照教程的建议使用 babel 渲染 JSX,我从浏览器控制台收到此错误。

“browser.min.js:4 Uncaught EvalError: 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' blob :文件系统:chrome-extension-resource:“。” screenshot of the error

我知道这违反了 CSP 指令,但我又该如何使用 babel 来使用最新的 reactJS?

最佳答案

在你的 manifest.json 文件中,你可以尝试设置

"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"

我从here得到了答案.这为我消除了错误,但我对它的了解还不足以了解其他含义,抱歉。

关于javascript - 在 Chrome 扩展中使用 React js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35229330/

相关文章:

javascript - 如何在meteorjs 上使用youtube 发帖?

google-chrome - 输入和选择元素在 Chrome + Safari 中添加了填充,但在 Firefox 中没有?

javascript - Chrome 错误地将语言环境应用于 CSSStyleSheet 中的值

google-chrome-extension - webm提取aac时,时长不一致

css - 如何真正隔离 Google Chrome 扩展中的样式表?

javascript - 如何调用 google chrome 扩展程序中的函数

javascript - "Uncaught TypeError: e.slice is not a function"传递json数据到"orchard"查看

javascript - 如何判断 HTML5 Canvas 性能缓慢的原因?

javascript - 将字符串拆分为两个单独的部分

jquery - 谷歌浏览器和 jquery 用户界面 : draggable object is moving away from mouse cursor