JSON
JSON in browser extensions provide data for rulesets, managed storage schemas, and more. Extension.js handles the inclusion, bundling, and processing of JSON files referenced in the manifest.json
, ensuring they are correctly emitted and added to the compilation output.
How Does It Work?
Extension.js performs the following tasks for JSON resources:
- Emit JSON Files: The JSON files referenced in the
manifest.json
are emitted to the output directory.
- Add to File Dependencies: JSON files are added to the file dependencies of the compilation, ensuring that any updates to the JSON files trigger a recompile.
- Error Handling: If a referenced JSON file is missing or incorrectly configured, warnings are generated to help developers fix issues during the build process.
JSON Support
The following manifest fields are used to declare JSON files:
Manifest Field |
File Type Expected |
declarative_net_request.rule_resources |
.json |
storage.managed_schema |
.json |
Sample JSON Declaration in manifest.json
Hereβs an example of how to declare a JSON file in your manifest.json
:
{
"manifest_version": 3,
"name": "My Extension",
"version": "1.0",
"declarative_net_request": {
"rule_resources": [
{
"id": "ruleset_1",
"enabled": true,
"path": "rules/ruleset.json"
}
]
},
"storage": {
"managed_schema": "schema/storage-schema.json"
}
}
This configuration ensures that Extension.js will process the JSON files and include them in the final output of your extension.
Output Path
The output path for JSON files follows a simple structure based on their context in the manifest. For example, the resulting files would look like this:
dist/
[browser]/
βββ declarative_net_request/
β βββ rule_resources-0.json
βββ storage/
β βββ managed_schema.json
βββ other-extension-files
Best Practices
- Use the
/public/
folder for additional JSON files that are not directly declared in the manifest.
- Ensure that JSON files are well-formed and follow the correct schema for their intended use (e.g., rulesets, managed schemas).
Next Steps
- Learn more about handling JSON files and other static assets via Special Folders.