This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
A Manifest V3 browser extension (Chrome, Edge, Firefox) for proxy profile management with auto-switch rules and PAC script support. It is an alternative to Proxy SwitchyOmega.
npm run build # Type-check (vue-tsc) + build for Chrome/Edge
npm run build:firefox # Type-check + build for Firefox (transforms manifest)
npm run dev # Vite dev server
npm test # Run vitest in watch mode
npm run coverage # Single run with coverage report
npx vitest run tests/services/proxy/profile2config.test.ts # Run a single test fileCI runs npm run coverage on PRs to main/develop; npm run build + npm run build:firefox on pushes and tags.
The Vite config defines three entry points that produce the extension bundle:
index.html/popup.html-- Both loadsrc/main.ts(Vue app). The Vue router uses hash history:#/popuprendersPopupPage,#/rendersConfigPagewith nested profile/preference routes.src/background.ts-- Service worker. Wires up proxy auth, request stats, and badge indicator. No Vue, no DOM.
BaseAdapter defines the abstract contract for all browser APIs (storage, proxy, webRequest, tabs, i18n). Concrete implementations: Chrome, Firefox, WebBrowser (dev stub). A singleton Host is auto-detected at import time and used everywhere. This is the only layer that touches chrome.* or browser.* APIs directly.
The core complexity lives here:
profile2config.ts--ProfileConverterturns aProxyProfileinto aProxyConfig(forchrome.proxy.settings). For non-PAC profiles and auto-switch profiles, it generates PAC scripts via AST usingescodegen/acornnode builders inscriptHelper.ts. Auto-switch profiles compose multiple sub-profiles by generatingregister()calls that build a lookup table.pacSimulator.ts-- JS reimplementations of PAC functions (shExpMatch,isInNet) used to simulate PAC evaluation in-extension (e.g., for tab badge resolution).isInNetreturnsUNKNOWNwhen given a hostname instead of an IP (can't do DNS in extension context).auth.ts-- Resolves proxy auth credentials by walking the profile tree (auto-switch profiles delegate to sub-profiles).
Profiles are stored in chrome.storage.local under key "profiles". Types: ProfileSimple (proxy/pac), ProfilePreset (system/direct), ProfileAutoSwitch (rule-based routing). System profiles DIRECT and SYSTEM have fixed IDs "direct" and "system".
Schema definitions for importing/exporting profile configurations using io-ts for runtime type validation.
deepClone() in src/services/utils.ts uses JSON.parse(JSON.stringify(obj)). Do not replace with structuredClone() -- Vue's reactive Proxy objects throw DataCloneError under structuredClone(). The JSON round-trip serializes through Vue's Proxy traps and produces plain objects safe for chrome.storage.
The vite.config.ts TRANSFORMER_CONFIG rewrites manifest.json at build time for Firefox:
- Replaces
background.service_workerwithbackground.scriptsarray - Removes
version_name - Adds
browser_specific_settings.gecko
@/ maps to src/ (configured in both vite.config.ts and tsconfig.json).
Translation strings live in public/_locales/{locale}/messages.json. Translations are managed via Transifex.