Manifest v3 资源必须列在 web_accessible_resources 中

spa*_*kle 3 google-chrome-extension

即使在 manifest.json 中正确声明了“image/copy.svg”,我也会收到此错误

拒绝加载 chrome-extension://pofbdjeepddggbelfghnndllidnalpde/images/copy.svg。资源必须在 web_accessible_resources 清单键中列出,以便由扩展程序之外的页面加载。

如果我去 chrome-extension://pofbdjeepddggbelfghnndllidnalpde/images/copy.svg 我可以成功地看到加载的图像。

css/style.css

.copy-icon{
    content:url('chrome-extension://__MSG_@@extension_id__/images/copy.svg');
    height: 16px;
    width: auto;
    margin-right: 0px;
}
Run Code Online (Sandbox Code Playgroud)

html

<button alt="Copy to clipboard" class="clipboard" data-clipboard-text="TEXT">
  <img class="copy-icon"></img>
</button> 
Run Code Online (Sandbox Code Playgroud)

清单文件

    "manifest_version": 3,
    "content_scripts": [
    {
      "matches": ["https://*.example.com/*"], 
      "js": ["contents/results.js"],
      "css": ["css/style.css"],
      "run_at": "document_end"
    }
  ],
    "web_accessible_resources": [{
        "resources": ["images/copy.svg"],
        "matches": [],
       "extension_ids": []
      }], 
Run Code Online (Sandbox Code Playgroud)

wOx*_*xOm 9

matches密钥应指定揭露这些资源。
您可以使用<all_urls>将它们暴露在任何地方。

"web_accessible_resources": [{
  "resources": ["images/copy.svg"],
  "matches": ["<all_urls>"],
}],
Run Code Online (Sandbox Code Playgroud)

  • 不,此功能涉及站点到扩展程序的访问,而不是扩展程序到站点的访问。 (4认同)