Close blank redirect tabs

This commit is contained in:
Ivan Grachyov 2021-12-11 23:03:37 +03:00
parent a02080db2f
commit f998a2c203

View File

@ -1,7 +1,25 @@
var pendingTabIds = {};
function handleUpdated(tabId, changeInfo, tabInfo) {
const prefix = "https://tokenary.io/blank/";
if (tabInfo.url.startsWith(prefix)) {
const id = tabInfo.url.replace(prefix, "");
if (id in pendingTabIds) {
const pendingTabId = pendingTabIds[id];
browser.tabs.update(pendingTabId, { active: true });
delete pendingTabIds[id];
}
browser.tabs.remove(tabId);
}
}
browser.tabs.onUpdated.addListener(handleUpdated);
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.subject === "closeTab") {
browser.tabs.remove(sender.tab.id);
} else if (request.subject === "process-inpage-message") {
pendingTabIds[request.message.id] = sender.tab.id; // TODO: Would be good not to save on macOS
browser.runtime.sendNativeMessage("mac.tokenary.io", request.message, function(response) {
sendResponse(response)
});
@ -13,6 +31,7 @@ browser.browserAction.onClicked.addListener(function(tab) {
const id = new Date().getTime() + Math.floor(Math.random() * 1000);
const request = {id: id, name: "switchAccount", object: {}, address: "", proxy: true};
browser.tabs.sendMessage(tab.id, request);
pendingTabIds[request.id] = tab.id; // TODO: Would be good not to save on macOS
// TODO: pass current network id
// TODO: pass favicon
// TODO: pass host here as well