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

0

Full article

tl;dr - No, pick one.

Alright, thanks for stopping by! Have a great rest of th....

What?

Oh, you expected a better explanation than that? Point taken, you probably ended up here because of an error, and not just randomly. Well, 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.

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

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

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

Author

Grant Winney

Is there anything more satisfying than sharing knowledge? Of teaching someone and witnessing their "ah ha" moment? I hope you found something here today that led to your very own "ah ha" moment! 💡


Comments