How to Load Local Images with CSS in Chrome Extensions?

DDD
Release: 2024-11-10 07:13:02
Original
315 people have browsed it

How to Load Local Images with CSS in Chrome Extensions?

Unable to Load Local Images with CSS in Google Chrome Extensions

For website modifications through content scripting within Chrome extensions, difficulties may arise when attempting to utilize local images. This issue persists despite incorporating the images within the extension.

The challenge stems from the specific CSS syntax used to reference local images:

body {
    background: #000 url('image.jpg') !important;
    background-repeat: repeat !important;
}
Copy after login

Solution

To address this limitation, Chrome i18n support offers a crucial solution:

  • Maintain your images in a designated "image" folder within the extension.
  • Reference assets in the CSS using the following syntax:
background-image:url('chrome-extension://__MSG_@@extension_id__/images/main.png');
Copy after login

Ensure that the images are included in the "web_accessible_resources" array in the manifest.json file, which grants permissions to access these resources from the extension.

The above is the detailed content of How to Load Local Images with CSS in Chrome Extensions?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template