Charles使用技巧
source link: https://ttys3.dev/post/charles/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
March 7, 2021
1. Linux 下 HiDPI 问题⚓
OS: Fedora 32 (Workstation Edition) GNOME 版本:3.36.3 Charles Proxy 版本: v4.5.6
通常在 GNOME3 下我们会将 Display 的 Scale 调成 200%
(当前还不支持非整数倍数设置) 来解决4K分辨率问题,如下图:
Charles官方也宣称它已经支持HiDPI了,但是实际使用却发现没有自动识别HiDPI,为什么呢?
我们看看/usr/bin/charles
这个启动脚本:
# HiDPI
if [ -x /usr/bin/gsettings ]; then
GDK_SCALE=$(/usr/bin/gsettings get org.gnome.desktop.interface scaling-factor | awk '{print $2}')
export GDK_SCALE
fi
如果我们执行gsettings list-recursively org.gnome.desktop.interface
看看就会发现,这个scaling-factor
(虽然是有这个key的)并没有被设置。因此,/usr/bin/gsettings get org.gnome.desktop.interface scaling-factor
的结果是:uint32 0
❯ /usr/bin/gsettings describe org.gnome.desktop.interface scaling-factor
Integer factor used to scale windows by. For use on high-dpi screens. 0 means pick automatically based on monitor.
根据
ArchLinux 的文档,这两种设置方法应该是等效的(但是上面的结果表示,
通过图片界面设置的display scale, 不会反应到 scaling-factor
):
To enable HiDPI, navigate to Settings > Devices > Displays > Scale and choose an appropriate value. Or, use gsettings:
$ gsettings set org.gnome.settings-daemon.plugins.xsettings overrides "[{'Gdk/WindowScalingFactor', <2>}]"
$ gsettings set org.gnome.desktop.interface scaling-factor 2
Note: GNOME only allows integer scaling numbers to be set. 1 = 100%, 2 = 200%, etc. See Fractional Scaling below.
因此,这里针对 Charles 最简单的解决办法就是执行 gsettings set org.gnome.desktop.interface scaling-factor 2
2. 启用 HTTPS 抓包⚓
光启用了这个还不行,对于 iOS 来说,还得安装 Charles 的根证书。
先将 iOS WLAN 的 HTTP 代理设置成 IP:8888
(8888是Charles的默认http代理监听端口), 然后在手机浏览器里打开 chls.pro/ssl
下载证书。
iOS 10 及以上版本必须额外操作来信任此证书。
我当前的iOS 版本为 13.4.1 , 不同的版本设置可能不太相同。这个入口还挺深的。
3. 过滤掉部分域名或只抓取部分域名⚓
右击一个请求,选择 ignore 即会自动将此URL添加到Recording Settings
里的 Exclude
, 一般我们都会想直接过滤整个域名,这个时候只需要“双击”编辑一下这个自动添加的项,去除 Path
和 Query
即可。
如果反过来,只想要白名单抓取的话,设置 Include
即可。
这些条目还可以非常方便地导出,方便导入到其它机器。
4. Protobuf 自动解包⚓
通过Viewer Mappings
设置,我们可以让Charles自动选择对应的消息类型解包,
而不需要每次请求完手动选项相应的消息类型。
以下是一个demo设置,这个请求发送的数据类型为json,但是响应是protobuf,
我们通过设置特定的 Path
来限制这个规则只应用于此 API:
如果是自定义的protobuf包,则可以通过View
-> Protobuf Settings
添加 *.desc 描述文件.
描述文件可通过以下命令生成:
protoc -oModel.desc Model.proto
需要注意的是,请求或响应头的Content-Type
字段必须要是application/x-protobuf
或 application/x-google-protobuf
, Charles才会自动识别为probobuf包
更多信息可参考 https://www.charlesproxy.com/documentation/using-charles/protocol-buffers/
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK