Files
holesail-browser/extension/background.js
T
Raven Scott 5c4f0b4aba
CI / Build & Test (push) Failing after 28s
efactor(extension): modularize dashboard, background, and docs
Split monolithic dashboard.js (2753 lines) into 18 focused modules
under dashboard/{core,data,ui,pages}/ with refresh.js and events.js
as orchestrators. Extracted ~900-line inline <style> into dashboard.css
and moved dashboard.html to dashboard/dashboard.html.

Split background.js (609 lines) into background/{logs,state,proxy,
native-messaging,tab-lifecycle,message-router}.js with a thin entry
point using importScripts().

Deleted dead files: wrong-domain.js (duplicate of inline script).
Updated manifest.json web_accessible_resources for new paths.
Updated docs/ARCHITECTURE.md to reflect the new file structure.

No functionality changed. No build step introduced.
2026-02-28 23:02:52 -05:00

55 lines
1.6 KiB
JavaScript

/**
* Background service worker entry point.
* Loads modules in dependency order via importScripts().
*/
const SW_VERSION = 3; // increment to force service worker reload detection
/** Set to true for super detailed debug logging. */
const DEBUG_VERBOSE = false;
const browser = (typeof chrome !== 'undefined' && chrome.runtime?.connectNative)
? chrome
: (globalThis.browser ?? chrome);
importScripts(
'background/logs.js',
'background/state.js',
'background/proxy.js',
'background/native-messaging.js',
'background/tab-lifecycle.js',
'background/message-router.js'
);
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' });
});