CI / Build & Test (push) Successful in 3m22s
Firefox MV3 does not support background.service_worker. Split background into background-boot.js (globals) and background-main.js (startup logic); Chrome keeps using importScripts() in background.js, Firefox manifest uses background.scripts with the same file list so the extension loads in both.
36 lines
1.2 KiB
JavaScript
36 lines
1.2 KiB
JavaScript
/**
|
|
* 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' });
|
|
});
|