I understand the conceptual differences between background and content scripts as there are plenty of articles and threads on it, but I’m not sure how these differences look in practice. I’m not sure exactly what makes a script a background script or a content script - it seems to be implicit, but I’m not sure based off what.
For example, in this example: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Your_second_WebExtension, there is a file called beastify.js in a folder called content_scripts, so I’m guessing that’s a content script. But there is another file called choose_beast.js in a directory called popup, and I’m not sure whether that counts as a background or a content script. I see no differences between beastify.js and choose_beast.js that should tip me off as to what type of file choose_beast.js is. Maybe I am overthinking this.
Which is it, and how can I tell based on the code in the file?
Make sure to read the Anatomy of web-extension, specifically the background scripts section:
Basically you have to specify in your manifest file which script(s) or html file will be used as background script.
Same way (in manifest file) you specify what script will be used as content script.
Additionally you can use Content script API (in Firefox only) and tab.executeScript to inject any of your script files into a page as content script (dynamically at runtime).
Content scripts are the ones injected into a webpage, and have limited access to web extension APIs. All other scripts – background, popup, siderbar, options – have full privileges, but they are each separate contexts that do not share scope. If the different contexts need to talk to each other, they must do so by sending messages.
To answer the question, the popup script is certainly more like a background script than a content script.
Popup scripts are invoked by their respective html files, as are sidebar and options scripts by theirs as well. These html files are usually specified in the manifest (though some can be specified from within the background script too).