Can I use background.html and background.js in the same Chrome extension?

Full article

In a word.. no. You're only allowed to specify either an array of scripts...

"background": {
    "persistent": false,
    "scripts": [ "jquery-1.2.3.js"]

... or a page, which can then reference the script(s) the page needs:

"background": {
    "persistent": false,
    "page": "background.html"

Your "background.html" page might be nothing else other than the same list of scripts you could specify in the "scripts" array, but the reason you'd usually choose an HTML page over a list of JS files is because you intend to add something else to it.

To each their own I guess.

    	<script src="jquery-1.2.3.js"></script>
    	<script src="anotherscript.js"></script>
    	<script src="whynotonemore.js"></script>

But if you try to specify both (which hopefully you've now realized is completely unnecessary), the extension just won't load:

The and background.scripts properties cannot be used at the same time. Could not load manifest.


Grant Winney

I write when I've got something to share - a personal project, a solution to a difficult problem, or just an idea. We learn by doing and sharing. We've all got something to contribute.

Comments / Reactions

One of the most enjoyable things about blogging is engaging with and learning from others. Leave a comment below with your questions, comments, or ideas. Let's start a conversation!