项目作者: bayandin

项目描述 :
Multiplexing proxy for Chrome DevTools. Fully compatible with Selenium and ChromeDriver
高级语言: Python
项目地址: git://github.com/bayandin/devtools-proxy.git
创建时间: 2016-07-24T19:56:49Z
项目社区:https://github.com/bayandin/devtools-proxy

开源协议:MIT License

下载


DevTools Proxy

Build Status
PyPI
GitHub release

DevTools Proxy is a tool for creating simultaneous connections via DevTools Protocol (which is not possible by default and it is possible since Chrome 63 even without DevTools Proxy).

How it works

  1. +---+ +---+
  2. | C | | |
  3. | L | | D | +-----------+
  4. | I | | E | | |
  5. | E |<---->| V | | BROWSER |
  6. | N | | T | | |
  7. | T | | O | | |
  8. +---+ | O | | +---+ |
  9. | L | | | T | |
  10. | S |<-----> | A | |
  11. +---+ | | | | B | |
  12. | C | | P | | +---+ |
  13. | L | | R | | |
  14. | I |<---->| O | | |
  15. | E | | X | | |
  16. | N | | Y | +-----------+
  17. | T | | |
  18. +---+ +---+

Installation

  • Download & unzip standalone binary for your system.
  • If you use Python (at least 3.6) you can install it via pip: pip install devtools-proxy

Usage

With Selenium and ChromeDriver

There are examples for Python and Ruby. Demos for CPU Throttling, Network requests and Remote debugging.

Standalone (for any language)

  • Configure ChromeOptions:
    • Set path to chrome-wrapper.sh as a binary. Optional arguments are mentioned in example for Python below
    • Add --devtools-proxy-binary=/path/to/devtools-proxy to args

Python

devtools-proxy pypi package supports at least Python 3.6. If you use lower Python version use Standalone package.

  1. pip install -U devtools-proxy
  1. from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
  2. from devtools.proxy import CHROME_WRAPPER_PATH
  3. devtools_proxy_binary = 'devtools-proxy' # Or path to `devtools-proxy` from downloaded binaries
  4. capabilities = DesiredCapabilities.CHROME.copy()
  5. capabilities['chromeOptions'] = {
  6. 'binary': CHROME_WRAPPER_PATH, # Or path to `chrome-wrapper.sh` from downloaded binaries
  7. 'args': [
  8. f'--devtools-proxy-binary={devtools_proxy_binary}',
  9. # Optional arguments:
  10. # '--chrome-binary=/path/to/chrome/binary', # Path to real Chrome/Chromium binary
  11. # '--devtools-proxy-chrome-debugging-port=some-free-port', # Port which proxy will listen. Default is 12222
  12. # '--devtools-proxy-args=--additional --devtools-proxy --arguments, # Additional arguments for devtools-proxy from `devtools-proxy --help`
  13. ],
  14. }

With multiple Devtools instances

  • Run devtools-proxy (by default it started on 9222 port)
  • Run Chrome with parameters --remote-debugging-port=12222 --remote-debugging-address=127.0.0.1
  • Open a website which you want to inspect
  • Open debugger in a new Chrome tab: http://localhost:9222 and choose your website to inspect
  • Repeat the previous step as many times as you need it