Temporary settings survival more resilient and compatible with Fenix.

This commit is contained in:
hackademix 2020-08-20 15:56:52 +02:00
parent fa81d3791a
commit 7785661d97
1 changed files with 35 additions and 18 deletions

View File

@ -75,26 +75,43 @@ var LifeCycle = (() => {
unrestrictedTabs: [...ns.unrestrictedTabs] unrestrictedTabs: [...ns.unrestrictedTabs]
})); }));
try {
await new Promise((resolve, reject) => { await new Promise((resolve, reject) => {
let done = false;
let l = async (tabId, changeInfo) => { let l = async (tabId, changeInfo) => {
if (done || tabId !== tab.id) return;
debug("Survival tab updating", changeInfo); debug("Survival tab updating", changeInfo);
if (changeInfo.status !== "complete") return; if (changeInfo.status !== "complete") return;
try { try {
await Messages.send("store", {url, data: toBase64(new Uint8Array(cypherText))}, {tabId, frameId: 0}); await Messages.send("store", {url, data: toBase64(new Uint8Array(cypherText))}, {tabId, frameId: 0});
done = true;
resolve(); resolve();
debug("Survival tab updated"); debug("Survival tab updated");
browser.tabs.onUpdated.removeListener(l);
} catch (e) { } catch (e) {
if (!Messages.isMissingEndpoint(e)) { if (!Messages.isMissingEndpoint(e)) {
error(e, "Survival tab failed"); error(e, "Survival tab failed");
reject(e); reject(e);
} // otherwise we keep waiting for further updates from the tab until content script is ready to answer } // otherwise we keep waiting for further updates from the tab until content script is ready to answer
return false;
}; };
return true;
};
try {
browser.tabs.onUpdated.addListener(l);
} catch (e) {
reject(e);
} }
browser.tabs.onUpdated.addListener(l, {tabId});
}); });
await Storage.set("local", { "updateInfo": {key, iv: toBase64(iv), tabId}}); await Storage.set("local", { "updateInfo": {key, iv: toBase64(iv), tabId}});
tabId = -1;
debug("Ready to reload...", await Storage.get("local", "updateInfo")); debug("Ready to reload...", await Storage.get("local", "updateInfo"));
} finally {
if (tabId !== -1 && !ns.local.debug) {
browser.tabs.remove(tabId); // cleanup on failure unless we want to debug a post-mortem
}
}
}, },
async retrieveAndDestroy() { async retrieveAndDestroy() {