A powerful Python script that leverages Selenium and Chrome DevTools Protocol (CDP) to capture, log, and analyze network traffic (Requests, Responses, and Headers) from a browser session. Ideally suited for debugging, monitoring, or analyzing web traffic with proxy support.
- Full Network Capture: Logs all HTTP requests, responses, and headers.
- Session Management: Automatically creates timestamped folders (e.g.,
session_20231027_123000) for each run to keep logs organized. - Proxy Support: Native support for authenticated proxies (
ip:port:user:pass) with automatic extension generation. - Stealth Mode: Includes basic anti-detection flags to avoid simple bot detection.
- Real-time Logging: Writes data to files immediately as traffic is captured.
git clone https://github.com/kunaldevelopers/browser-network-traffic-logger.git
cd browser-network-traffic-loggerEnsure you have Python installed, then run:
pip install -r requirements.txtNote: This project requires Google Chrome to be installed on your machine.
If you wish to use proxies, create a file named proxy.txt in the root directory. Add your proxies line-by-line in the following format:
ip:port:username:password
Example proxy.txt:
192.168.1.1:8080:user123:pass456
10.0.0.5:3128:admin:secret
If the file is missing or empty, the script will run without a proxy.
Run the script directly with Python:
python network_logger.py- The script launches a Chrome browser window.
- It constantly monitors network events (
Network.requestWillBeSent,Network.responseReceived). - You can manually navigate the web in the opened window.
- All traffic is logged into a new
session_YYYYMMDD_HHMMSSfolder. - Press
Ctrl+Cin the terminal to stop the logger.
After a session, you will find a new folder containing:
session_20231027_153000/
├── 📄 requests.txt # Details of all outgoing HTTP requests (URL, Method, POST Data)
├── 📄 responses.txt # Details of incoming responses (Status, Remote IP)
└── 📄 headers.txt # Full request and response headers
sequenceDiagram
participant User
participant Script
participant Browser
participant Network
participant Files
User->>Script: Run network_logger.py
Script->>Script: Create Session Folder
Script->>Browser: Launch Chrome (with Proxy)
Script->>Browser: Enable Network Debugging
Browser->>Network: Request Page
Network-->>Browser: Return Data
Browser->>Script: Send Network Event (CDP)
Script->>Files: Write to requests.txt / responses.txt
User->>Script: Ctrl+C (Stop)
Script->>Browser: Close Browser
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
Repository Link: https://github.com/kunaldevelopers/browser-network-traffic-logger