mirror of
https://github.com/skidoodle/hostinfo
synced 2026-04-28 01:27:36 +02:00
Add host info views and network error handling
Introduce modular host info UI components: Header, InfoRow, CopyButton, and Browser/Local/Public views. Refactor ServerInfo to compose these components. Add network error handling: background listens for webRequest onErrorOccurred and forwards errors to Tab.handleError. Implement Tab.handleError to store friendly error info and Tab.processSystemPage to handle browser/system pages.
This commit is contained in:
@@ -13,17 +13,33 @@ export default defineBackground({
|
||||
{ urls: ['<all_urls>'] }
|
||||
);
|
||||
|
||||
// Listen for Network Errors (DNS, Connection Refused, etc.)
|
||||
browser.webRequest.onErrorOccurred.addListener(
|
||||
async (details) => {
|
||||
if (details.tabId === -1 || details.type !== 'main_frame') return;
|
||||
await Tab.handleError(details.tabId, details.url, details.error);
|
||||
},
|
||||
{ urls: ['<all_urls>'] }
|
||||
);
|
||||
|
||||
// Listen for Navigation
|
||||
browser.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
|
||||
if (changeInfo.status === 'complete' && tab.url && tab.url.startsWith('http')) {
|
||||
// We might not have the IP yet if it was cached, so we trigger a process
|
||||
// If IP is missing, Tab waits or we can force a HEAD request here
|
||||
await Tab.process(tabId, tab.url);
|
||||
if (changeInfo.status === 'complete' && tab.url) {
|
||||
const urlObj = new URL(tab.url);
|
||||
const isSystemPage = ['chrome:', 'about:', 'edge:', 'moz-extension:', 'chrome-extension:', 'file:'].includes(urlObj.protocol);
|
||||
|
||||
// Force connection to ensure webRequest fires if cached
|
||||
try {
|
||||
await fetch(tab.url, { method: 'HEAD', cache: 'no-store', mode: 'no-cors' });
|
||||
} catch { /* ignore */ }
|
||||
if (isSystemPage) {
|
||||
await Tab.processSystemPage(tabId);
|
||||
} else if (tab.url.startsWith('http')) {
|
||||
// We might not have the IP yet if it was cached, so we trigger a process
|
||||
// If IP is missing, Tab waits or we can force a HEAD request here
|
||||
await Tab.process(tabId, tab.url);
|
||||
|
||||
// Force connection to ensure webRequest fires if cached
|
||||
try {
|
||||
await fetch(tab.url, { method: 'HEAD', cache: 'no-store', mode: 'no-cors' });
|
||||
} catch { /* ignore */ }
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user