Skip to content

Commit c25ff6e

Browse files
committed
Remove the js errors for missing favicons and use the favicon api for Manifest v3
1 parent 9f79653 commit c25ff6e

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

js/spaces.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,19 @@ function renderTabListEl(tab, space) {
160160
const linkEl = document.createElement('a');
161161
const faviconEl = document.createElement('img');
162162

163-
// try to get best favicon url path
163+
// Use the provided favicon URL if it exists and is not a generic Chrome theme icon.
164164
if (tab.favIconUrl && tab.favIconUrl.indexOf('chrome://theme') < 0) {
165165
faviconSrc = tab.favIconUrl;
166-
} else {
167-
// TODO(codedread): Fix this, it errors.
168-
//faviconSrc = `chrome://favicon/${tab.url}`;
166+
// Otherwise, if the tab has a URL, construct a URL to fetch the favicon
167+
// via the extension's _favicon API. This is the recommended approach for Manifest V3.
168+
} else if (tab.url) {
169+
const pageUrl = encodeURIComponent(tab.url);
170+
faviconSrc = `chrome-extension://${chrome.runtime.id}/_favicon/?pageUrl=${pageUrl}&size=16`;
171+
}
172+
173+
if (faviconSrc) {
174+
faviconEl.setAttribute('src', faviconSrc);
169175
}
170-
faviconEl.setAttribute('src', faviconSrc);
171176

172177
linkEl.innerHTML = escapeHtml(tab.title ?? tab.url);
173178
linkEl.setAttribute('href', tab.url);

0 commit comments

Comments
 (0)