嗨,我正在开发一个简单的 chrome 扩展,它通过在扩展的 .crx 目录中打开一个 index.html 来替换当前默认的新标签页。
目前新标签页已经修改了新的 index.html 页面,但是标签上没有图标。
我可以问为什么吗?非常感谢!
当前新标签页打开时标签页没有图标的问题
Current Problem
扩展目录如下:
directory
manifest.json的代码如下
{
"manifest_version": 2,
"name": "千山",
"version": "0.1.0",
"description": "测试",
"icons": {"16": "icon200.png", "48": "icon200.png", "128": "icon200.png"},
"browser_action": {
"default_icon": "icon.png" ,
"default_title": "测试",
"default_popup": "popup.html"
},
"chrome_url_overrides": {
"newtab": "index.html"
}
}
index.html 的 head 如下,其实我写了但是没有显示
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>千山</title>
<!-- Bootstrap -->
<link href="bootstrap.min.css" rel="stylesheet">
<link rel="icon" href="fav.ico" type="image/x-icon">
最佳答案
您需要用文件的完整扩展路径替换相对路径“fav.ico”。在 JavaScript 中,您可以通过调用 chrome.runtime.getURL("fav.ico")
获取完整路径。
如果您知道完整路径并采取预防措施以确保您的扩展程序的 ID 不会随着时间的推移而改变(通过始终使用相同的 key.pem
文件发布),那么对路径进行硬编码将有效并且不需要任何 JavaScript。
您可能还需要将“fav.ico”添加到 web_accessible_resources
的 manifest.json
部分:
{
"web_accessible_resources": [
"fav.ico",
"bootstrap.min.css"
]
}
关于javascript - Chrome 扩展 : Open html in the crx file with no icon on tab,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29802740/