English | 简体中文
A modern HTTP request forwarding and debugging tool for developers, built with React, TypeScript, and Manifest V3.
Tribute to the Classic: This project is deeply inspired by xswitch. Thanks to the original author @yize for contributing to the developer community.
Why Rewrite: With the release of Chrome Extension Manifest V3, the classic xswitch extension can no longer run properly in modern browsers due to its V2 specification. To continue the life of this excellent tool while maintaining the familiar user experience developers love, we rebuilt this modernized version from scratch.
Alternative Recommendations: If Switch V3 doesn't meet your needs, we also recommend these excellent similar extensions:
- Shanhaiguan - Powerful request interception tool
- Camora - Simple and practical proxy switcher
💻 Development Note: This project was developed with AI assistance and completed in two and a half days. While we've conducted testing, as a rapid iteration project, there may be some edge case bugs. If you encounter issues during use, please submit an Issue, and we'll actively fix and improve.
- 🔄 Request Forwarding: Redirect HTTP requests using string matching or regular expressions
- 🌐 CORS Support: Automatically handle Cross-Origin Resource Sharing
- 📝 Code Editor: Advanced CodeMirror 6 editor with syntax highlighting and real-time validation
- 🗂️ Group Management: Organize rules into different groups with enable/disable controls
- ⚡ Performance: Optimized for fast rule matching and low memory usage
- 🎨 Modern UI: Built with Ant Design 5 for a clean, professional interface
- 🔧 Developer Friendly: Easy configuration import/export and debugging tools
- 🌍 Internationalization: Complete Chinese and English support with automatic browser language detection
- 🚀 Auto-Save: Debounced auto-save functionality for seamless editing experience
- 🔍 Real-time Validation: JSON format validation with error highlighting
- 📱 Responsive Design: Works perfectly in both popup and tab modes
-
Clone this repository
git clone <repository-url> cd xswitch-v3
-
Install dependencies
pnpm install
-
Build the extension
pnpm run build
-
Load the extension in Chrome
- Open Chrome and navigate to
chrome://extensions/ - Enable "Developer mode" in the top right
- Click "Load unpacked" and select the
distfolder
- Open Chrome and navigate to
# Install dependencies
pnpm install
# Start development server with hot reload
pnpm run dev
# Start development for Firefox
pnpm run dev:firefox
# Build for production
pnpm run build
# Build for Firefox
pnpm run build:firefox
# Create distribution zip
pnpm run zip
# Type checking
pnpm run compile
# Linting and formatting
pnpm run lint
pnpm run lint:fix
pnpm run format
pnpm run format:check
# Testing
pnpm run test # Run tests in watch mode
pnpm run test:run # Run tests once
pnpm run test:ui # Run tests with UI
pnpm run test:coverage # Run tests with coverage{
"proxy": [
["https://api.example.com", "http://localhost:3000"],
["(.*).example.com", "http://localhost:8080"]
],
"cors": ["api.example.com", "(.*).example.com"]
}- String Match: Direct string replacement
- Regex Match: Pattern matching with regular expressions (use
(.*)prefix)
{
"proxy": [["https://api.production.com", "http://localhost:3000"]]
}{
"proxy": [
["https://api.prod.com", "https://api.staging.com"],
["https://cdn.prod.com", "https://cdn.dev.com"]
]
}{
"proxy": [
["(.*).api.com/v1", "$1.api.com/v2"],
["(.*)production.com", "$1staging.com"]
],
"cors": ["(.*).api.com"]
}This extension uses Chrome's latest Manifest V3 specification:
- Service Worker: Replaces background pages for better performance and security
- declarativeNetRequest: Modern API for request interception with better performance
- Enhanced Security: Improved permissions model and content security policies
- Frontend: React 19 + TypeScript
- UI Library: Ant Design 5
- State Management: ahooks (useRequest, useMemoizedFn, useDebounceFn)
- Build Tool: WXT (Next-generation Vite-based extension framework)
- Code Editor: CodeMirror 6 with JSON syntax highlighting
- Package Manager: pnpm
- Testing: Vitest + jsdom
- Linting: ESLint + Prettier
entrypoints/
├── background.ts # Service worker entry point
├── background/
│ ├── controllers/ # Message handling controllers
│ ├── dao/ # Data access layer
│ ├── services/ # Business logic services
│ └── types/ # API type definitions
├── popup/
│ ├── App.tsx # Main popup interface
│ ├── api/ # API client modules
│ ├── components/ # Reusable UI components
│ ├── services/ # Frontend services
│ └── utils/ # Utility functions
├── utils/ # Shared utilities
└── content.ts # Content script entry
tests/
├── integration/ # End-to-end tests
├── unit/ # Unit tests
├── mocks/ # Test mocks
└── fixtures/ # Test data
types/ # Shared TypeScript definitions
- Chrome 88+ (Manifest V3 support)
- Edge 88+ (Chromium-based)
- Firefox 109+ (with
pnpm run build:firefox)
The extension follows a clean layered architecture:
- Background Layer: Service worker with controllers, services, and data access objects
- UI Layer: React-based popup interface with modern hooks and state management
- Communication Layer: Type-safe message passing with locale support
- Shared Layer: Common utilities and internationalization
- Modular Design: Clear separation of concerns with controllers, services, and DAOs
- Type Safety: Full TypeScript coverage with strict type checking
- State Management: Reactive state using ahooks with automatic data synchronization
- Debounced Operations: Auto-save with performance optimization
- Error Handling: Comprehensive error boundaries and user-friendly feedback
- Internationalization: Runtime language switching with persistent preferences
- Quick Creation: Use the popup interface for rapid rule creation
- Format Support: Rules support both string matching and regex patterns
- Organization: Groups help organize related rules logically
- Validation: Real-time JSON format checking with error highlighting
- Management: Easy enable/disable, edit, copy, and delete operations
- Navigate to
chrome://extensions/ - Find "Switch V3" and click "service worker" to debug background scripts
- Monitor console logs for request processing and rule matching
- Right-click the extension icon → "Inspect popup"
- Use React DevTools for component state inspection
- Check console for frontend errors and state changes
- Open DevTools → Network tab to observe request redirections
- Check Console for rule matching logs and performance metrics
- Use the extension's real-time feedback for rule validation
The project includes comprehensive testing infrastructure:
# Run all tests with watch mode
pnpm run test
# Run specific test files
pnpm run test -- json.test.ts
pnpm run test -- storage.test.ts
# Generate detailed coverage report
pnpm run test:coverage
# Run tests with visual interface
pnpm run test:ui- Smart Caching: Rules are compiled and cached for lightning-fast matching
- Debounced Saves: Configuration changes are batched to minimize I/O operations
- Efficient Regex: Patterns are compiled once and reused across requests
- Memory Management: Minimal memory footprint with automatic garbage collection
- Lazy Loading: Components and resources loaded on demand
- Local Storage: All data stored locally in Chrome storage with no external dependencies
- Minimal Permissions: Requests only essential permissions for core functionality
- Content Security Policy: Strict CSP implementation for enhanced security
- No External Requests: Extension operates entirely offline after installation
- Type Safety: TypeScript prevents common security vulnerabilities
- Input Validation: Comprehensive validation for all user inputs and configurations
interface GroupRuleVo {
id: string;
groupName: string;
ruleText: string; // JSON string containing proxy and cors rules
enabled: boolean;
createTime: string;
updateTime: string;
}
interface RuleConfig {
proxy: [string, string][]; // [source, target] pairs
cors?: string[]; // Domains with CORS enabled
}The extension exposes these APIs for frontend-backend communication:
LOAD_GROUPS: Load all rule groups with metadataSAVE_GROUP: Save a single rule group with validationCREATE_GROUP: Create new rule group with defaultsUPDATE_GROUP: Update existing rule group propertiesDELETE_GROUP: Remove rule group and cleanupTOGGLE_GROUP: Enable/disable rule group stateCLEAR_ALL_DATA: Reset all data to factory defaults
We welcome contributions from the community! Please follow these guidelines:
-
Fork the repository and create your feature branch
git checkout -b feature/amazing-feature
-
Set up development environment
pnpm install pnpm run dev
-
Make your changes with proper TypeScript types and documentation
-
Add comprehensive tests for new functionality
pnpm run test pnpm run test:coverage -
Ensure code quality
pnpm run lint:fix pnpm run format pnpm run compile
-
Use conventional commits
git commit -m "feat: add amazing feature" git commit -m "fix: resolve issue with rule matching" git commit -m "docs: update API documentation"
-
Submit a pull request with clear description and screenshots if applicable
- TypeScript: Follow strict mode requirements and provide comprehensive types
- React Patterns: Use modern hooks patterns with ahooks for state management
- Testing: Maintain test coverage above 80% for all new code
- Code Style: Follow existing patterns and use provided linting configuration
- Documentation: Update documentation for any API changes or new features
- Internationalization: Add translations for any user-facing text
- All submissions require review from maintainers
- Automated tests must pass before merge
- Code style and type checks must pass
- Documentation updates should accompany feature changes
- Import/Export: Configuration backup and sharing functionality
- Rule Templates: Pre-built rule sets for common development scenarios
- Advanced Filtering: Support for request headers and HTTP methods
- Performance Dashboard: Real-time statistics and rule matching metrics
- Rule Testing: Built-in testing tools for rule validation
- Advanced Editor: Enhanced code editor with autocomplete and validation
- Sync Support: Cross-device rule synchronization (optional)
- Team Collaboration: Shared rule sets for development teams
- Plugin System: Extensible architecture for custom rule processors
MIT License - see LICENSE file for details
- Complete Manifest V3 Compatibility: Full migration to modern Chrome extension APIs
- Modern React 19 Architecture: Latest React with concurrent features and TypeScript
- CodeMirror 6 Integration: Advanced code editor with syntax highlighting
- Comprehensive Internationalization: Runtime language switching with persistent preferences
- Auto-Save Functionality: Debounced auto-save with visual feedback
- Real-time Validation: JSON format validation with error highlighting
- ahooks Integration: Modern React hooks for better state management
- WXT Build System: Next-generation Vite-based build system
- Comprehensive Testing: Vitest-based testing with high coverage
- Type Safety: Strict TypeScript configuration with full type coverage
- Performance Optimization: Smart caching and efficient rule matching
- Ant Design 5: Modern, accessible UI components
- Responsive Design: Perfect experience in both popup and tab modes
- Light Theme: Clean and consistent light theme design
- Improved Accessibility: Full keyboard navigation and screen reader support
- 📋 Issues: Report bugs and request features on GitHub Issues
- 💬 Discussions: Join community discussions for usage questions and tips
- 📖 Documentation: Comprehensive guides in this README and inline code comments
- 🔧 Development: Follow the contributing guidelines above
- 🌍 Translations: Help improve internationalization support
- 📝 Documentation: Contribute to documentation and examples
-
Export Configuration: Save your existing rules from the old extension
-
Install Switch V3: Follow the installation guide above
-
Convert Rules: Transform to the new JSON format:
{ "proxy": [ ["https://old-api.com", "https://new-api.com"], ["(.*).staging.com", "$1.development.com"] ], "cors": ["api.example.com"] } -
Test Thoroughly: Verify that all rules work as expected
-
Enjoy New Features: Take advantage of improved performance and new capabilities
- Structured Format: More explicit and validated JSON configuration
- Better Performance: Optimized rule matching and lower resource usage
- Enhanced UI: Modern interface with better usability
- Future-Proof: Built on latest web standards and best practices
The migration provides significant improvements in stability, performance, and user experience.