通过chrome-extension添加@ font-face样式表规则的推荐方法是什么?问题是字体嵌入的url位于扩展内,所以我必须在javascript中使用才能使用chrome.extension.getURL
.
我尝试document.styleSheets[0].addRule
过内容脚本,但是没有用.为了澄清,我也有web_accessible_resources下列出的字体.
javascript css font-face google-chrome-extension content-script
即使在 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)