Surge Module Usage Guide
I had previously ignored Surge Modules. Although I had installed some modules contributed by others, I hadn’t carefully compared them or experienced their benefits. Recently, after reading some materials and practicing, I found that they are very suitable for certain scenarios, and suddenly felt they were truly amazing.
Module Introduction
Let me introduce a few points about modules for better understanding.
- According to the official explanation, a module patches the current profile, so it can be part of the configuration
- Limited support for Rules, MitM, etc. See details here
- Module configuration has higher priority than the current Profile, and multiple Modules execute in order, with later ones overriding earlier ones
- Module enabled states are not synced between devices, although the configuration itself is synced
- Profiles now support including profile fragments. For example, you can put the rule section in a separate file and include it in the main profile. However, note that profile fragments must be complete sections - you can’t have rules in both the main profile and profile sub-files. This differs from modules
Module修改
Module中JS修改后,不需要重启
cron修改需要重启
调试
JS中可以使用console.log
进行打印输出,日志文件支持查看
Mac下位置在这里
iPhone下位置在这里
我的使用情况
关于module的使用,当前我有以下几个实践
- 安装第三方module,比如招商银行/京东自动签到这种小羊毛,另外一个好处是也有利于我理解web安全,HTTP请求等
- 需要注意第三方module一般是本地托管一个地址,surge负责自动更新,但module也有窃取个人信息的风险,这点注意,不要轻易安装不明来源的第三方module
- 部分module需要解密MITM,如果开启太多,也会影响性能,因此按需安装/开启,不宜过多。
- 自行开发module,比如MitM all,很多时候为了抓取一个app下的请求需要HTTPS解密,但现在app 请求的服务端并非只有一个,发现一个配置一个的效率太低,于是可以直接模块形式配置解密所有网址/IP的,这样如果需要时,直接模块开启。平时关闭即可
已安装的module
自动签到领取X铜币,长期混迹v2,问问题/回答都需要花费币,因此自动签到很需要
临时开启对于所有站点的MitM
爱奇艺自动签到
京东自动签到,获取京豆,虽然不多,但毕竟是钱,何必浪费
显示ShadowSocks机场订阅详情,比如剩余流量
同时推荐下载第三方module地址,可以访问寻找社区贡献的module,如果满足不了自己的需求,可以自行开发实现:
[https://github.com/lhie1/Rules/tree/master/Surge/Surge%203/Module](https://github.com/lhie1/Rules/tree/master/Surge/Surge 3/Module)
注意
module配置修改后,需要重启Surge生效
举例JD DailyBonus
了解module实现,有助于更好的使用。以JD这个模块为例,并不是安装启用后就可以直接使用,阅读模块中的注释说明,了解模块具体使用
- 访问https://bean.m.jd.com
- 手机提示写入cookie成功,则可正常使用
- 签到执行实际会按照配置的cron规则执行

原理
当我们访问https://bean.m.jd.com时,surge会解密HTTPS请求信息,获取cookie,写入Surge的持久化存储中,这样自动JOB没到指定时间,即可以发起签到API请求。
Surge API
module如果想做开关,手动去点太过低效,好在Surge API开放了module操作,Mac端可以使用Alfred workflow实现
如果是手机端,考虑捷径/shortcut解决,因为surge有run script支持。
常见问题
invalid module
注意配置中设备类型限制,比如
#!system=Mac
则iPhone导入会报错Error: The Profile file can’t be parsed: Failed to load detached section from: xxxxxxx.dconf
iOS 端 Profile Sync 开启选 iCloud Drive
写在最后
Surge确实好用,但使用门槛并不低,正如官方介绍,其主要是面向开发者使用。