Merge pull request #373 from Jaxx7594/icon-race

fix: Favicon race condition
This commit is contained in:
Seth Burkart
2026-02-01 09:53:14 +11:00
committed by GitHub
+32 -4
View File
@@ -50,13 +50,31 @@ async function init() {
documentLoadStyle.textContent = documentLoadCSS; documentLoadStyle.textContent = documentLoadCSS;
document.head.appendChild(documentLoadStyle); document.head.appendChild(documentLoadStyle);
const icons = replaceIcons();
document.querySelectorAll<HTMLLinkElement>('link[rel*="icon"]');
icons.forEach((link) => { const observer = new MutationObserver((mutations) => {
link.href = icon48; for (const mutation of mutations) {
if (
mutation.type === "attributes" &&
mutation.target instanceof HTMLLinkElement &&
mutation.target.rel.includes("icon") &&
mutation.attributeName === "href"
) {
replaceIcons();
return;
}
}
}); });
observer.observe(document.head, {
subtree: true,
attributes: true,
attributeFilter: ["href"],
});
try { try {
await initializeSettingsState(); await initializeSettingsState();
@@ -85,3 +103,13 @@ async function init() {
} }
} }
} }
function replaceIcons() {
document
.querySelectorAll<HTMLLinkElement>('link[rel*="icon"]')
.forEach((link) => {
if (link.href !== icon48) {
link.href = icon48;
}
});
}