“Refused to execute inline script” in ReactJS Chro

2019-09-15 18:21发布

问题:

I am familiar with Chrome's policy on inline scripts in Extensions. However, I don't think I have one in my files? All I have is very basic and I'm just attempting to place an input field onto the page.

main.js:

class Container extends React.Component {
    render() {
        return (
            <div className="locationSearchBarContainer">
                <SearchBar />
            </div>
        );
    }
}

class SearchBar extends React.Component {
    render() {
        return (
            <input className="searchBar" id="locationSearchBar" />
        );
    }
}

ReactDOM.render(
    <Container />,
    document.getElementById('container')
);

main.html:

<!doctype html>
<html>
  <head>
    <title>New Tab</title>
    <script src="../scripts/plugins/react.min.js"></script>
    <script src="../scripts/plugins/react-dom.min.js"></script>
    <script src="../scripts/plugins/babel.min.js" charset="utf-8"></script>
    <script src="../scripts/main.js" type="text/babel"></script>
  </head>
  <body>
    <div id="container"></div>
  </body>
</html>

manifest.json

{
  "manifest_version": 2,

  "name": "",
  "description": "See what's happening around you and add events to your calendar",
  "version": "0.01",

  "browser_action": {
    "default_icon": "img/icon.png",
    "default_title": "Click here!"
  },
  "chrome_url_overrides" : {
    "newtab": "html/main.html"
  },
  "permissions": [
    "activeTab"
  ]
}

回答1:

I believe the problem is that in this version of Babel you can't just prototype a site and include the library in a script tag, or it'll execute in-line. I don't have this problem anymore going through the Browserify route.