Reputation: 2261
I'm trying to implement jQuery in my Chrome Extension in order to include the firebase.js in my background.js (which seems already weird), however chrome refuses to execute code from inside the jquery.js.
background.js
$.getScript('firebase.js', function()
{
// code depending on firebase.js, jquery is just needed here to include firebase.js
});
popup.html
<html>
<head>
<script src="jquery-3.0.0.min.js"></script>
<script src="firebase.js"></script>
<script src="popup.js"></script>
<script src="background.js"></script>
</head>
<body>
//stuff happens
</body>
</html>
manifest.json
"content_scripts":[
{
"js":["jquery-3.0.0.min.js"],
"all_frames":true
}
],
"background": {
"scripts": ["background.js"],
"persistent": true
},
So for me it looks like it is included properly, however I am getting this, which is very weird, since it is inside the jquery library:
jquery-3.0.0.min.js:2 Refused to execute inline script because it violates the following Content Security Policy
Isn't there another method on how to include Firebase.js in the background.js? It makes no sense that it doesn't work there, it is included in my popup.html.
Upvotes: 1
Views: 193
Reputation: 14657
The error comes from
$.getScript('firebase.js', function() { ...
jQuery's getScript
will fetch the code in the file and then create a <script>
element with the code as its text. That would be an inline script that is forbidden by the Content Security Policy.
If you want to include a file just before your code in background.js
you can simply put:
"scripts": ["firebase.js", "background.js"],
in your manifest.json.
Upvotes: 1