mirror of
https://github.com/skidoodle/hostinfo
synced 2026-04-28 09:37:37 +02:00
fix lookup
This commit is contained in:
+42
-12
@@ -74,15 +74,30 @@ async function initTab(tabId: number, url: string, resolveDns = false) {
|
||||
|
||||
applyIconForState(tabId, newState);
|
||||
|
||||
if (!isSystem && !hasExistingData && resolveDns) {
|
||||
const ip = await DnsService.resolve(domain);
|
||||
if (ip) {
|
||||
await processIp(tabId, url, ip);
|
||||
if (!isSystem && !hasExistingData) {
|
||||
const performDnsFallback = async () => {
|
||||
const state = tabStates.get(tabId);
|
||||
if (state?.status !== 'loading' || state.url !== url) return;
|
||||
|
||||
const ip = await DnsService.resolve(domain);
|
||||
|
||||
const stateAfterDns = tabStates.get(tabId);
|
||||
if (stateAfterDns?.status !== 'loading' || stateAfterDns.url !== url) return;
|
||||
|
||||
if (ip) {
|
||||
await processIp(tabId, url, ip);
|
||||
} else {
|
||||
await updateState(tabId, {
|
||||
status: 'error',
|
||||
errorMessage: 'Could not resolve host'
|
||||
}, url);
|
||||
}
|
||||
};
|
||||
|
||||
if (resolveDns) {
|
||||
await performDnsFallback();
|
||||
} else {
|
||||
await updateState(tabId, {
|
||||
status: 'error',
|
||||
errorMessage: 'Could not resolve host'
|
||||
});
|
||||
setTimeout(performDnsFallback, 1500);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -132,13 +147,14 @@ async function processIp(tabId: number, url: string, ip: string) {
|
||||
applyIconForState(tabId, newState);
|
||||
}
|
||||
|
||||
async function updateState(tabId: number, updates: Partial<TabState>) {
|
||||
async function updateState(tabId: number, updates: Partial<TabState>, expectedUrl?: string) {
|
||||
let current = tabStates.get(tabId);
|
||||
if (!current) {
|
||||
current = await StorageService.getTabState(tabId) || undefined;
|
||||
}
|
||||
|
||||
if (current) {
|
||||
if (expectedUrl && current.url !== expectedUrl) return;
|
||||
const newState = { ...current, ...updates };
|
||||
tabStates.set(tabId, newState);
|
||||
await StorageService.setTabState(tabId, newState);
|
||||
@@ -194,13 +210,16 @@ export default defineBackground({
|
||||
}
|
||||
const ip = await DnsService.resolve(hostname);
|
||||
|
||||
const currentState = tabStates.get(details.tabId);
|
||||
if (currentState?.status !== 'loading' || currentState.url !== details.url) return;
|
||||
|
||||
if (ip) {
|
||||
await processIp(details.tabId, details.url, ip);
|
||||
} else {
|
||||
await updateState(details.tabId, {
|
||||
status: 'error',
|
||||
errorMessage: 'Could not resolve host'
|
||||
});
|
||||
}, details.url);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -208,12 +227,23 @@ export default defineBackground({
|
||||
browser.webRequest.onErrorOccurred.addListener(
|
||||
async (details) => {
|
||||
if (details.type !== 'main_frame') return;
|
||||
if (details.error === 'net::ERR_ABORTED') return;
|
||||
if (details.error === 'net::ERR_ABORTED') {
|
||||
try {
|
||||
const tab = await browser.tabs.get(details.tabId);
|
||||
if (tab.url) {
|
||||
const currentState = tabStates.get(details.tabId);
|
||||
if (currentState && currentState.url !== tab.url) {
|
||||
initTab(tab.id!, tab.url, true);
|
||||
}
|
||||
}
|
||||
} catch { }
|
||||
return;
|
||||
}
|
||||
|
||||
await updateState(details.tabId, {
|
||||
status: 'error',
|
||||
errorMessage: details.error
|
||||
});
|
||||
}, details.url);
|
||||
},
|
||||
{ urls: ['<all_urls>'] }
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user