Web-accessible resources are files within an extension that can be accessed by web pages or other extensions. These resources are often used for images, scripts, or stylesheets that are required by content scripts or pages embedded within an extension's context.
Extension.js ensures proper handling of web_accessible_resources
paths in your manifest.json
, including assets imported in content scripts. This feature allows you to expose certain files from your extension to external web pages or make them available for other parts of the extension.
The following manifest field is used to declare web-accessible resources:
Manifest Field | File Type Expected | HMR Support |
---|---|---|
web_accessible_resources |
Any file type | Yes |
manifest.json
FileHere's an example of how to declare web-accessible resources in the manifest.json
file:
In this example, the web_accessible_resources
field exposes specific resources (images, scripts, styles) for web pages that match the pattern defined in matches
.
manifest.json
If you need to include additional files as web-accessible resources but prefer not to declare them directly in the manifest.json
, you can place these files in the /public
folder. Extension.js will automatically process and make them accessible without needing to modify the manifest.
Example Usage:
Place your web-accessible files in the /public
folder for automatic handling:
For more information, refer to the Special Folders documentation.
The output path for web-accessible resources will follow the structure defined in your manifest or the /public
folder. The resulting files will look like this:
The plugin responsible for handling web-accessible resources in Extension.js performs the following tasks:
manifest.json
file with paths for web-accessible resources based on the content scripts and assets being used.web_accessible_resources
if they are intended to be accessible by web pages or other external scripts./public
folder to keep your manifest.json
clean and organized.