Skip to content

Commit 696fdc9

Browse files
committed
fix favicons in chrome
1 parent 11bc84d commit 696fdc9

3 files changed

Lines changed: 23 additions & 17 deletions

File tree

chrome/src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "New Tab Page Bookmarks",
33
"description": "Displays your bookmarks in multiple columns for quick access from the new tab page",
4-
"version": "1.10",
4+
"version": "1.11",
55
"manifest_version": 3,
66
"author": "https://github.com/mathio",
77
"chrome_url_overrides": {

firefox/src/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "New Tab Page Bookmarks",
33
"description": "Displays your bookmarks in multiple columns for quick access from the new tab page",
4-
"version": "1.10",
4+
"version": "1.11",
55
"manifest_version": 2,
66
"author": "https://github.com/mathio",
77
"chrome_url_overrides": {

src/index.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
import { decodeBlurHash } from './fast-blurhash.js'
22

3-
const isFirefox = typeof browser !== 'undefined'
3+
const getChromeIconUrl = (pageUrl) => {
4+
try {
5+
const url = new URL(chrome.runtime.getURL('/_favicon/'))
6+
url.searchParams.set('pageUrl', pageUrl)
7+
url.searchParams.set('size', '32')
8+
return url.toString()
9+
} catch {
10+
return null
11+
}
12+
}
413

5-
export const DEFAULT_ICON_SVG = `data:image/svg+xml,${encodeURIComponent(
6-
'<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="gray" viewBox="0 0 16 16"><path d="M0 8a8 8 0 1 1 16 0A8 8 0 0 1 0 8m7.5-6.923c-.67.204-1.335.82-1.887 1.855A8 8 0 0 0 5.145 4H7.5zM4.09 4a9.3 9.3 0 0 1 .64-1.539 7 7 0 0 1 .597-.933A7.03 7.03 0 0 0 2.255 4zm-.582 3.5c.03-.877.138-1.718.312-2.5H1.674a7 7 0 0 0-.656 2.5zM4.847 5a12.5 12.5 0 0 0-.338 2.5H7.5V5zM8.5 5v2.5h2.99a12.5 12.5 0 0 0-.337-2.5zM4.51 8.5a12.5 12.5 0 0 0 .337 2.5H7.5V8.5zm3.99 0V11h2.653c.187-.765.306-1.608.338-2.5zM5.145 12q.208.58.468 1.068c.552 1.035 1.218 1.65 1.887 1.855V12zm.182 2.472a7 7 0 0 1-.597-.933A9.3 9.3 0 0 1 4.09 12H2.255a7 7 0 0 0 3.072 2.472M3.82 11a13.7 13.7 0 0 1-.312-2.5h-2.49c.062.89.291 1.733.656 2.5zm6.853 3.472A7 7 0 0 0 13.745 12H11.91a9.3 9.3 0 0 1-.64 1.539 7 7 0 0 1-.597.933M8.5 12v2.923c.67-.204 1.335-.82 1.887-1.855q.26-.487.468-1.068zm3.68-1h2.146c.365-.767.594-1.61.656-2.5h-2.49a13.7 13.7 0 0 1-.312 2.5m2.802-3.5a7 7 0 0 0-.656-2.5H12.18c.174.782.282 1.623.312 2.5zM11.27 2.461c.247.464.462.98.64 1.539h1.835a7 7 0 0 0-3.072-2.472c.218.284.418.598.597.933M10.855 4a8 8 0 0 0-.468-1.068C9.835 1.897 9.17 1.282 8.5 1.077V4z"/></svg>'
7-
)}`
14+
const getFallbackIconUrl = (pageUrl) => {
15+
const { hostname } = new URL(pageUrl)
16+
return `https://icons.duckduckgo.com/ip3/${hostname}.ico`
17+
}
818

9-
const getFavicon = (pageUrl) => {
10-
if (isFirefox) {
11-
const { hostname } = new URL(pageUrl)
12-
return `https://icons.duckduckgo.com/ip3/${hostname}.ico`
13-
}
14-
const url = new URL(chrome.runtime.getURL('/_favicon/'))
15-
url.searchParams.set('pageUrl', pageUrl)
16-
url.searchParams.set('size', '32')
17-
return url.toString()
19+
const getFaviconUrl = (pageUrl) => {
20+
return getChromeIconUrl(pageUrl) || getFallbackIconUrl(pageUrl)
1821
}
1922

2023
const addElm = (parent, tag, text, attributes) => {
@@ -58,9 +61,12 @@ const renderNode =
5861

5962
li.append(link)
6063

61-
icon.src = getFavicon(href)
64+
icon.src = getFaviconUrl(href)
6265
icon.onerror = () => {
63-
icon.src = DEFAULT_ICON_SVG
66+
const fallbackUrl = getFallbackIconUrl(href)
67+
if (icon.src !== fallbackUrl) {
68+
icon.src = fallbackUrl
69+
}
6470
}
6571
}
6672
}

0 commit comments

Comments
 (0)