简体   繁体   English

用于 Chrome 扩展的 React 组件未呈现

[英]React Component for Chrome Extension not rendering

I am building a Chrome Extension using React.我正在使用 React 构建 Chrome 扩展。 Right now I am trying to put my react component into the popup for the extension.现在我正试图将我的反应组件放入扩展的弹出窗口中。 It renders fine on a plain webpage (localhost:3000), however when I add my index.html as the default_popup in my manifest.json, only a very small white box pops up.它在普通网页 (localhost:3000) 上呈现良好,但是当我将 index.html 添加为 manifest.json 中的 default_popup 时,只会弹出一个非常小的白色框。 I saw another post that said this is a Content Security Policy and that locating the SHA256 in the error would fix it.我看到另一篇文章说这是一个内容安全策略,在错误中定位 SHA256 可以解决它。 However, I have not found any errors in my console.但是,我在控制台中没有发现任何错误。 Please help.请帮忙。 I have not really changed the code from the basic react-app, here are my manifest.json and App.js files我还没有真正更改基本 react-app 的代码,这里是我的 manifest.json 和 App.js 文件

 <div className="App"> <header className="App-header"> <img src={logo} className="App-logo" alt="logo" /> <p> Price on stockX: <code>src/App.js</code> and save to reload. </p> <a className="App-link" href="https://reactjs.org" target="_blank" rel="noopener noreferrer" > Learn React </a> </header> </div>

 { "short_name": "React App", "name": "q React App Sample", "version": "1.0", "manifest_version": 2, "browser_action": { "default_popup": "index.html", "default_title": "stockUp" }, "start_url": ".", "display": "standalone", "theme_color": "#000000", "background_color": "#ffffff" }

You must first build the code and then insert it into an extension.您必须首先构建代码,然后将其插入到扩展中。

  • npm run build npm 运行构建
  • cross-check manifest.json file and icons交叉检查 manifest.json 文件和图标
  • goto chrome extension转到 chrome 扩展
  • goto load unpacked option转到加载解压选项
  • load build folder It works加载构建文件夹它有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM