Skip to content

Commit 0beed6c

Browse files
committed
Work-around for Chromium unable to load the placeholder icon.
1 parent a4a7967 commit 0beed6c

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

content/PlaceHolder.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,47 @@ var PlaceHolder = (() => {
3636
l.type = "text/css";
3737
document.head.appendChild(l);
3838
}
39+
3940
}
4041
};
4142

4243
var theme;
44+
var chromiumBgStyle;
4345
let updateTheme = replacement => {
46+
let {style} = replacement;
4447
if (theme === undefined) {
45-
replacement.style.backgroundImage = "none";
4648
(async () => {
4749
try {
4850
theme = await Messages.send("getTheme");
4951
} catch (e) {
5052
theme = "";
5153
}
54+
style.backgroundImage = "";
5255
updateTheme(replacement);
5356
})();
5457
return;
5558
}
5659
if (theme) {
5760
replacement.classList.add(theme);
5861
}
59-
replacement.style.backgroundImage = "";
62+
if (UA.isMozilla) {
63+
replacement.classList.add("mozilla");
64+
} else {
65+
// Chromium doesn't resolve CSS URIs relative to the extension, but to the site.
66+
// Let's fetch the bg image as a data URI and apply it in a <style> element.
67+
if (!chromiumBgStyle) {
68+
chromiumBgStyle = createHTMLElement("style");
69+
const img = getComputedStyle(replacement).getPropertyValue("--img-logo");
70+
if (img) {
71+
(async () => {
72+
const url = img.replace(/\\/g, '').replace(/.*(\/img\/[^'")]+).*/, "$1");
73+
chromiumBgStyle.textContent =
74+
`${SELECTOR} { background-image: url(${await Messages.send("fetchResource", {url})}) !important }`;
75+
document.head.appendChild(chromiumBgStyle);
76+
})();
77+
}
78+
}
79+
}
6080
};
6181

6282

0 commit comments

Comments
 (0)