Closed James-E-A closed 4 years ago
contributed solution from some people online (they requested not to be credited per se)
have not tested/evaluated yet
I may refactor further
//foreground.js
function loadDidComplete() {
browser.runtime.sendMessage("PAGE_LOAD_COMPLETED");
}
if (document.readyState === "complete") {
loadDidComplete();
} else {
window.addEventListener('DOMContentLoaded', loadDidComplete);
}
//background.js
var pageLoadCallbacks = {};
browser.runtime.onMessage.addListener((message, sender, callback) => {
if (message === "PAGE_LOAD_COMPLETED") {
if (sender.url in pageLoadCallbacks) {
var pageLoadCallback = pageLoadCallbacks[sender.url];
pageLoadCallback();
delete pageLoadCallbacks[sender.url];
}
}
});
browser.webRequest.onHeadersReceived.addListener(
async (details) => {
...
pageLoadCallbacks[details.url] = () => {
browser.browserAction.setIcon({
tabId: tabId,
path: path
});
browser.browserAction.setTitle({
tabId: tabId,
title: rootHost||`?? ${fp} ??`
});
}
...
Closed by 6dfb4beee58588c73995b6c4e45a0afec7869c10
fix one bug, induce 2 more
If you load 2 tabs: Google, and Sectigo, the icon will stay stuck at the logo of the second one you loaded, rather than being set appropriately on a per-tab basis.
Every time a new tab loads, it changes the icon across all tabs
If you look at the code, it's a simple enough "fix" to set
tabId
when setting the icon… but, when I do this, it instantly (like, 1 frame later) goes back to the default icon. ARGH.