Using Mitmproxy for Automated Mobile H5 Performance Testing
The article introduces a comprehensive H5 performance automation platform for mobile devices that combines a management console, agents, mitmproxy, and Harviewer to capture, process, and visualize HTTP/HTTPS traffic, addressing limitations of traditional tools like Charles and Fiddler.
Mobile H5 performance testing often relies on tools such as Charles or Fiddler, which can be cumbersome and lack effective result management and analysis. To overcome these issues, a dedicated H5 performance automation platform is proposed, consisting of a management platform, agents, mitmproxy, and Harviewer.
Platform components:
The management platform handles test task scheduling, machine allocation, command distribution, and result querying.
Agents execute commands from the platform, start the proxy, and run automation scripts that drive the mobile device to access specified URLs.
Mitmproxy captures both HTTP and HTTPS traffic via a man‑in‑the‑middle proxy. Its advantages include cross‑platform Python implementation, command‑line operation, and the ability to run custom scripts that directly generate HAR files.
Harviewer is an open‑source tool that visualizes HAR files as request waterfall charts.
The article then focuses on how to use mitmproxy for capturing HTTP/HTTPS requests.
Why choose mitmproxy? Traditional tools like tcpdump cannot capture HTTPS traffic, and the resulting PCAP files lack detailed HTTPS information. Since many modern services use HTTPS, a proxy‑based solution is required, and mitmproxy was selected after evaluation.
Mitmproxy offers three interfaces: mitmproxy (interactive UI), mitmdump (command‑line), and mitmweb (web UI). For automation, mitmdump is preferred because it can run scripts to process captured data.
Example command using mitmdump with a custom script to generate a HAR file:
./venv/bin/mitmdump -s examples/complex/har_dump1.py --set hardump=dump.har -p 4002This command runs the har_dump1.py script, which converts the captured stream into a HAR file named dump.har and listens on port 4002.
After setting up mitmproxy, the mobile device must be configured to use the proxy (IP and port matching mitmproxy's listening port). The user then visits mitm.it on the device to download and trust the mitmproxy certificate (located at ~/.mitmproxy/ if manual installation is needed).
Once the certificate is trusted, the device can capture HTTPS traffic via mitmproxy. The article promises future updates on generating HAR files with mitmdump and further automation details.
转转QA
In the era of knowledge sharing, discover 转转QA from a new perspective.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.