Icon not found
Content scripts are JavaScript files that run in the context of web pages. In Extension.js, these scripts are essential for interacting with web pages, modifying their content, and accessing page elements. Content scripts allow your extension to add custom functionality to specific pages or web applications.
Extension.js manages content scripts by performing the following actions:
content_scripts
field of the manifest.json
are compiled, bundled, and emitted.The following fields in the manifest.json
are used for declaring content scripts and related resources:
Manifest Field | File Type Expected | HMR Support |
---|---|---|
content_scripts.js |
.js, .ts, .mjs, .tsx | Yes |
content_scripts.css |
.css, .scss, .less, .sass | Yes |
Below is an example of how to declare content scripts within the manifest.json
file:
This configuration specifies that the content-script.js
JavaScript file and content-style.css
CSS file should run on all web pages.
To include additional content scripts outside the manifest.json
, place them in the /scripts
folder. This approach allows you to modularize your scripts for better code organization.
Example Usage:
Content scripts are output to the following directory:
/scripts
folder to keep content scripts organized and modular.