清单 v3 资源必须列在 web_accessible_resources

Manifest v3 Resources must be listed in the web_accessible_resources

即使在 manifest.json

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

Denying load of chrome-extension://pofbdjeepddggbelfghnndllidnalpde/images/copy.svg. Resources must be listed in the web_accessible_resources manifest key in order to be loaded by pages outside the extension.

如果我转到 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;
}

html

<button alt="Copy to clipboard" class="clipboard" data-clipboard-text="TEXT">
  <img class="copy-icon"></img>
</button> 

manifest.json

    "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": []
      }], 

matches 键应指定公开这些资源的位置。
您可以使用 <all_urls> 将它们暴露在任何地方。

"web_accessible_resources": [{
  "resources": ["images/copy.svg"],
  "matches": ["<all_urls>"],
}],