"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to Load Local Images in CSS for Chrome Extensions?

How to Load Local Images in CSS for Chrome Extensions?

Published on 2024-11-16
Browse:102

How to Load Local Images in CSS for Chrome Extensions?

Troubleshooting Local Image Loading in Google Chrome Extensions

Despite incorporating local images within a Chrome extension, users encounter difficulties displaying them using CSS. This issue warrants addressing.

The core issue lies in Chrome's i18n support, which allows CSS references to extension assets. To resolve this, consider the following:

  1. Place images in an "image" folder within the extension.
  2. Reference images in CSS using the following syntax:
background-image:url('chrome-extension://__MSG_@@extension_id__/images/main.png');
  1. Ensure the referenced image is listed in the "web_accessible_resources" array in manifest.json.

By implementing these steps, local images can be successfully loaded and displayed using CSS within Chrome extensions.

Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3