我正在开发Google Chrome浏览器扩展程序,并且面临着背景方面的挑战;浏览器不会加载CSS中添加的背景图片。

我似乎找不到在web_accessible_resources文件中的manifest.json键下声明 Assets 的有效方法。

什么是manifest.json文件,如何在其中声明 Assets ?

最佳答案

任何Chrome扩展程序都需要manifest.json文件。 manifest.json文件包含定义扩展名的信息。文件中信息的格式为JSON

您可以在Google Chrome开发者文档中阅读有关它包含的内容的更多信息:Manifest File Format

您可能还需要阅读:Overview of Google Chrome Extensions

一个相对简单的manifest.json文件如下所示(来源:Getting Started: Building a Chrome Extension):

{
  "manifest_version": 2,

  "name": "Getting started example",
  "description": "This extension shows a Google Image search result for the current page",
  "version": "1.0",

  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  },
  "permissions": [
    "activeTab",
    "https://ajax.googleapis.com/"
  ]
}

Manifest - Web Accessible Resources:

这是分配给manifest.json文件中的关键字web_accessible_resources的字符串数组,该字符串指定了扩展程序中可由网页访问的 Assets 。 manifest.json中的文件/路径相对于扩展名的根目录。该网页可以通过类似于chrome-extension://[PACKAGE ID]/[PATH]的URL访问资源。

示例(来源:Manifest - Web Accessible Resources):
{
  ...
  "web_accessible_resources": [
    "images/*.png",
    "style/double-rainbow.css",
    "script/double-rainbow.js",
    "script/main.js",
    "templates/*"
  ],
  ...
}

有关web_accessible_resources的更多信息,请参阅Google Chrome开发者文档:Manifest - Web Accessible Resources

关于google-chrome-extension - Google Chrome浏览器扩展manifest.json文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39312748/

10-12 16:19