Does not recognize js for the extension

2

I'm trying to do extensions for chrome and my html file does not recognize the js

File manifest.json

"content_scripts": [ {
    "matches": ["https://*/*"],
    "js": ["app.js"],// este js si lo reconoce
    "css": ["app.css"]
  } ],
  "browser_action": {
    "default_popup": "app.html",// este html si lo reconoce
    "default_title": "capture!"
  },

app.html file

<head>
    <script src="function.js"></script> // este archivo js no lo reconoce

the structure of the tree is:

    
asked by hubman 24.07.2018 в 19:19
source

3 answers

1

With these one of these two options should work: Add the path in the file in the manifest.json

"js": ["app.js", "function.js"]

Or change invoke it like this:

<script src="./function.js" type="text/javascript"></script>

I also recommend you create a js folder and put all the javascript files there so that everything is more ordered, then to invoke it you just have to do:

<script src="js/function.js" type="text/javascript"></script>

Regarding the type="text / javascript" it is not necessary to include it since in html5 this is the default type but for compatibility with older versions of the browser it is always better to put it.

If the above does not work for you, try adding your function.js file in the manifest.json to the accessible resources

"web_accessible_resources": ["function.js"]
    
answered by 01.08.2018 / 06:53
source
1

It is important to keep in mind that linking external JavaScript files either in the <head> or before the closing tag </body> depends on the project and / or the way you are working on your code.

Try to link it before the closing tag </body> or as follows <script src="./function.js"></script> .

    
answered by 29.07.2018 в 01:55
1

try adding the script in the manifest.json in the array of js:

"content_scripts": [ {
"matches": ["https://*/*"],
"js": ["app.js", "function.js"]
"css": ["app.css"]
}],
    
answered by 30.07.2018 в 23:15