Favicon未显示在新标签Chrome扩展程序中

时间:2016-03-29 08:40:45

标签: html google-chrome google-chrome-extension favicon

我正在构建一个覆盖新标签的Chrome Extension。我设法用我的HTML文件和页面标题覆盖新选项卡。但是,favicon不会显示在新选项卡上,也不会显示错误。

这是我的manifest.json

{
  "manifest_version": 2,
  "name": "Hello World",

  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  },
  "chrome_url_overrides" : {
    "newtab": "hello_world.html"
  },
  "permissions": [
    "activeTab",
    "tabs"
  ]
}

以下是hello_world.html

<html>
<head>
  <title>Hello World</title>
  <link rel="shortcut icon" href="favicon.ico"/>
</head>  
 <body>
  <div>Hello World</div>  
 </body>
</html>

我在docs中找不到有关新标签上的favicon的内容。

1 个答案:

答案 0 :(得分:1)

您必须在清单中将favicon.ico添加到web_accessible_resources,以便hello_world.html可以访问它。然后,您必须动态更改您的favicon的hrefchrome.extension.getURL("favicon.ico")的结果。

将此添加到您的清单:"web_accessible_resources": [ "favicon.ico" ]

编辑:删除了代码示例,因为它没有工作并添加了新代码。

如果您覆盖historybookmarks页面,则此代码正常工作,因为默认情况下它们具有favicon。只需在清单中更改此内容,即可试用head hello_world.html <title>Hello World</title> <link rel="shortcut icon" href="chrome-extension://{ID OF YOUR EXTENSION}/favicon.ico" /> 到下面的代码。

newtab

遗憾的是,无法在public static void main(String[] args) throws IOException { String fromclient; ServerSocket Server = new ServerSocket(25000); System.out.println("TCPServer Waiting for client on port 25000"); while (true) { Socket connected = Server.accept(); System.out.println( " THE CLIENT" + " " + connected.getInetAddress() + ":" + connected.getPort() + " IS CONNECTED "); PrintWriter out = new PrintWriter(connected.getOutputStream(), true); Scanner sc = new Scanner(System.in); while (true) { String input = sc.nextLine(); out.println(input); } } } 页面添加图标。我希望没有它可以活下去;)