/** * Background main logic (after all modules loaded). * Used by both Chrome (via importScripts from background.js) and Firefox (via background.scripts). */ log('background: SW started v' + SW_VERSION); // Apply PAC immediately on startup using default port; updated once native host connects applyPAC(); connect(); // Redirect *.host.test (and similar typos) to extension page so we can show "use .hole.sail" const WRONG_DOMAIN_RULE_ID = 1; if (browser.declarativeNetRequest && browser.runtime.getURL) { const redirectUrl = browser.runtime.getURL('wrong-domain.html') + '?host=\\1'; browser.declarativeNetRequest.updateDynamicRules({ removeRuleIds: [WRONG_DOMAIN_RULE_ID], addRules: [{ id: WRONG_DOMAIN_RULE_ID, priority: 1, condition: { regexFilter: '^https?://([^/:]+)\\.host\\.test($|/)', resourceTypes: ['main_frame'] }, action: { type: 'redirect', redirect: { regexSubstitution: redirectUrl } } }] }).catch((err) => log('declarativeNetRequest rule failed:', err.message)); } // Open dashboard when extension icon is clicked browser.action?.onClicked?.addListener((tab) => { browser.tabs.create({ url: 'dashboard/dashboard.html' }); });