Kai
Kai

Reputation: 2325

chrome extension background page error: "Uncaught SyntaxError: Unexpected token <"

Why is my background.html page throwing this:

Uncaught SyntaxError: Unexpected token < in line 1

Here is the actual html:

<html>
<head>
<script type="text/javascript" src="fancy-settings/source/lib/store.js"></script>
<script type="text/javascript" src="background.js"></script>
</head>
<body></body>
</html>

So chrome complains about the first opening "<" and I have no idea why.

Upvotes: 8

Views: 5190

Answers (3)

Chandragupt
Chandragupt

Reputation: 11

If you are using Manifest V3, just add type: "module" in the background

     {
        ...
        "background": {
        "service_worker": "background.js",
        "type": "module"
        },
        ...
     }

Upvotes: 0

Alexandro S&#225;nchez
Alexandro S&#225;nchez

Reputation: 175

I had the same issue. Just replace in your manifest.json file

"background": {
    "scripts": ["background.js"]
  },

with:

"background": {
    "page": "background.html"
  },

Upvotes: 6

Mediator
Mediator

Reputation: 15378

remove js:

<script type="text/javascript" src="fancy-settings/source/lib/store.js"></script>
<script type="text/javascript" src="background.js"></script>

If the error persists, then you are not hooked up correctly js

Upvotes: 1

Related Questions