SwitchyOmega Browser Extension Setup
Relevant source files
The following files were used as context for generating this wiki page:
The Self-Rule repository provides a comprehensive collection of rule lists designed for proxy tools like Clash and Surge. These same rule lists can be effectively utilized with the SwitchyOmega browser extension to enable sophisticated, automatic proxy switching. SwitchyOmega allows users to manage multiple proxy settings and define rules to automatically decide whether a website should be accessed through a proxy or a direct connection.
This guide explains how to configure SwitchyOmega using the rule sets available in this repository. It covers the setup of auto-switch profiles, the types of rule lists provided, and how to import them into the extension. This allows for fine-grained control over web traffic, such as bypassing the GFW, blocking advertisements, and ensuring direct access to domestic services.
System Architecture
SwitchyOmega acts as an intermediary within the browser, intercepting web requests and routing them according to user-defined rules. When used with a proxy client like Clash (which is also configured in this repository), the system directs traffic designated for proxying to the local Clash port.
The following diagram illustrates the data flow from the browser to the internet, managed by SwitchyOmega and a local proxy client.
This diagram shows how SwitchyOmega uses rule lists from the repository to route browser traffic either directly to the internet or through a local proxy client.
Sources: Clash/GeneralClashConfig.yml:5, Tool/SwitchyOmega/规则列表设置.txt
Key Features and Rule Lists
The repository contains several types of rule lists, primarily in YAML format for Clash, which can be adapted for SwitchyOmega. These lists serve different purposes, from bypassing firewalls to blocking ads.
Rule List Overview
The primary value of this repository is its curated collection of domain and IP lists. The update_providers.py script is used to process .list files and generate .yaml provider files for Clash, demonstrating the project's focus on rule management.
Sources: update_providers.py:12-30
| Rule List File/Section | Purpose | Example Rule |
|---|---|---|
Clash/Providers/ProxyGFWlist.yaml | A comprehensive list of domains and IPs that typically require a proxy to access from mainland China. | DOMAIN-SUFFIX,google.com |
Clash/Providers/ProxyLite.yaml | A more lightweight version of the proxy list, containing essential domains. | DOMAIN-KEYWORD,google |
Clash/GeneralClashConfig.yml (cfw-bypass) | A list of domains that should be accessed directly, bypassing any proxy. This is useful for domestic services and LAN addresses. | *.bilibili.com |
Clash/Providers/BanProgramAD.yaml | A collection of rules to block advertisements in various applications and websites. | DOMAIN-SUFFIX,ad.xiaomi.com |
Clash/Providers/Ruleset/ | A directory of specialized rule sets for specific services like AI, Github, and Scholar. | DOMAIN-SUFFIX,openai.com |
Sources: Clash/Providers/ProxyGFWlist.yaml, Clash/Providers/ProxyLite.yaml, Clash/GeneralClashConfig.yml:256-650, Clash/Providers/BanProgramAD.yaml, Clash/Providers/Ruleset/AI.yaml
Configuration in SwitchyOmega
To use the rules from this repository, you need to configure an "Auto Switch" profile in SwitchyOmega. This profile will automatically switch between a direct connection and your proxy based on the URL being accessed.
1. Create Profiles
First, create two basic profiles:
- Proxy Profile: Configure this to point to your local proxy client (e.g., Clash). The default for Clash is typically
SOCKS5on host127.0.0.1and port7890or7891. - Direct Profile: This profile makes direct connections without a proxy.
Sources: Clash/GeneralClashConfig.yml:5-11
2. Set up Auto Switch Profile
The core of the setup is the "Auto Switch" profile. This profile uses a rule list to determine which profile to use for a given request.
The file Tool/SwitchyOmega/规则列表设置.txt contains a configuration snippet for importing an online rule list. This demonstrates the recommended approach.
Auto Switch Logic
The following flowchart shows how the Auto Switch profile processes a request.
Sources: Tool/SwitchyOmega/规则列表设置.txt
3. Importing a Rule List
You can import rule lists directly from an online URL.
- In your "Auto Switch" profile, click "Add rule list".
- For "Rule List Format", select AutoProxy.
- For "Rule List URL", you can use a raw link to a compatible rule list. The repository's
.yamlfiles are for Clash, but the principles are the same. You would typically use a pre-converted list compatible with the AutoProxy format. The fileTool/SwitchyOmega/规则列表设置.txtreferences usinghttps://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txtas a rule list URL.
The rules from the repository, such as ProxyGFWlist.yaml, serve as the source of truth for what should be proxied.
Sources: Tool/SwitchyOmega/规则列表设置.txt, Clash/Providers/ProxyGFWlist.yaml.
Rule Syntax and Management
The rule lists in this repository primarily use a format for Clash/Surge, but the patterns can be easily translated to SwitchyOmega's format.
Rule Type Mapping
| Clash/Surge Syntax | SwitchyOmega Equivalent | Description |
|---|---|---|
DOMAIN-SUFFIX,xyz.com | *.xyz.com (Wildcard) | Matches xyz.com and all its subdomains. |
DOMAIN-KEYWORD,xyz | *xyz* (Wildcard) | Matches any URL containing the keyword xyz. |
DOMAIN,xyz.com | xyz.com (Wildcard) | Matches the exact domain xyz.com. |
IP-CIDR,1.2.3.0/24 | 1.2.3.0/24 (Host/IP) | Matches any IP address within the specified CIDR range. |
Sources: Clash/Providers/ProxyGFWlist.yaml:4-3000, Clash/GeneralClashConfig.yml:258-260
The repository also includes tools for rule conversion, such as the Notepad++ macros found in Tool/Surge转acl工具/shortcuts.xml. These macros contain regular expressions for converting between formats like DOMAIN-SUFFIX and regex-based ACL rules, highlighting the project's focus on rule manipulation and maintenance.
Sources: Tool/Surge转acl工具/shortcuts.xml:18-25
Conclusion
The Self-Rule repository is a powerful resource for maintaining up-to-date proxy rule lists. By configuring the SwitchyOmega browser extension to use these lists, users can achieve a highly automated and efficient browsing experience, seamlessly switching between direct and proxied connections. The extensive ProxyGFWlist.yaml and cfw-bypass list from GeneralClashConfig.yml provide a solid foundation for a robust auto-switching setup that requires minimal manual intervention.