为了账号安全,请及时绑定邮箱和手机立即绑定

React Web Extension 错误:拒绝应用内联样式,因为它违反了以下内容安全

React Web Extension 错误:拒绝应用内联样式,因为它违反了以下内容安全

互换的青春 2023-01-06 16:10:48
我以前曾合作过,React Js但这是我第一次使用 React 进行 Web 扩展。My manifest.json file is:{  "manifest_version": 2,  "name": "owl",  "author": "zubayr",  "version": "1.0.1",  "description": "Testing!",  "icons": {    "16": "owl.png",    "48": "owl.png",    "128": "owl.png"  },  "browser_action": {    "default_popup": "index.html",    "default_title": "Open the popup"  },  "permissions": ["storage"]}我有一个奇怪的错误:Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' blob: filesystem:". Either the 'unsafe-inline' keyword, a hash ('sha256-1kri9uKG6Gd9VbixGzyFE/kaQIHihYFdxFKKhgz3b80='), or a nonce ('nonce-...') is required to enable inline execution.请让我知道出了什么问题。我的index.html文件是:<!DOCTYPE html><html>  <head>    <meta charset="utf-8" />    <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />    <meta name="viewport" content="width=device-width, initial-scale=1" />    <meta name="theme-color" content="#000000" />    <meta http-equiv="Content-Security-Policy" content="base-uri 'self'; object-src 'none'; script-src 'self' 'sha256-GgRxrVOKNdB4LrRsVPDSbzvfdV4UqglmviH9GoBJ5jk='; style-src 'self'">    <meta      name="description"      content="Web site created using create-react-app"    />    <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />    <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />    <style>    .myDiv {      border: 50px outset red;      background-color: '#000000';      text-align: center;    }    div {  height: 200px;  width: 50%;  background-color: powderblue;}另外,当我在 chrome 中以开发人员模式运行扩展程序时,弹出窗口与图像一样大。我似乎无法根据自己的意愿增加它的高度宽度。如果可能的话,也请告诉我它的解决方案。
查看完整描述

1 回答

?
慕莱坞森

TA贡献1810条经验 获得超4个赞

Chrome 安全性阻止了 create-react-app 生成的内联 JS。尝试这个

在您的 React 应用程序中,请创建一个.env或将其添加到现有应用程序中

INLINE_RUNTIME_CHUNK=false

然后构建您的应用程序(例如。yarn run build

使用这个,没有独立于大小的脚本被内联。

查看此拉取请求以获取更多详细信息https://github.com/facebook/create-react-app/pull/5354


查看完整回答
反对 回复 2023-01-06
  • 1 回答
  • 0 关注
  • 90 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信