Icons are used in various parts of the extension interface, including the toolbar, context menus, and the extension settings. Extension.js ensures that all icons defined in the manifest.json
file are correctly processed and emitted to the output directory during the build process.
Extension.js performs the following tasks for icon resources:
manifest.json
are emitted to the output directory of the compilation, ensuring that any updates to the icon files trigger a recompile..png
, .jpg
, and .svg
.The following manifest fields are used to declare icons:
Manifest Field | File Type Expected |
---|---|
action.default_icon |
.png, .jpg, .svg |
browser_action.default_icon |
.png, .jpg, .svg |
icons |
.png, .jpg, .svg |
page_action.default_icon |
.png, .jpg, .svg |
sidebar_action.default_icon |
.png, .jpg, .svg (*) |
Note: Support for
.svg
is currently partial in some browsers forsidebar_action.default_icon
. Review browser compatibility before using SVGs in this context.
Icons can appear in different locations across the browser interface, based on where theyβre declared in manifest.json
:
action.default_icon
or browser_action.default_icon
fields add an icon in the browser's toolbar, making it visible next to the address bar for user interaction.page_action.default_icon
provides a unique icon specific to certain pages, visible only when defined pages are active.icons
field are used in browser settings or the extension management interface. These icons represent the extension and are usually visible within the browser's extension settings page.sidebar_action.default_icon
icon appears within the side panel of supported browsers, such as Firefox, when the extension opens a custom sidebar interface.manifest.json
Below is a basic example of how to declare icons in your manifest.json
:
When referencing icons in HTML files, icons will be available in the dist
folder after building and within a folder based on the feature type. If you want to prevent this behavior, you can use the public
folder to store icons and other assets.
public
folderAssume the following project structure:
Add the following code to your HTML file to reference the icon:
Assume the following project structure:
Add the following code to your HTML file to reference the icon:
The output path for icons will be as follows:
You can import icons in JavaScript files using either the import
syntax or by referencing the icon path directly via the chrome.runtime.getURL
method.
Assume the following project structure:
Add the following code to your JavaScript file to reference the icon:
The output path for icons follows a structure based on their declared manifest fields. After building, icons are located within the dist/[browser]/
directory, organized as follows:
/public/
Folder: Place additional icons not declared in the manifest within the /public
folder to keep project structure clear and ensure theyβre accessible if needed.manifest.json
: Always declare icons in the manifest file to ensure theyβre correctly bundled in the build process.16px
, 48px
, 128px
) to support various device pixel ratios, ensuring icons display clearly on all devices.