browsermob-proxy icon indicating copy to clipboard operation
browsermob-proxy copied to clipboard

How do i get headers from Browsermob-proxy?

Open imoshe opened this issue 6 years ago • 2 comments

What i need : Proxy server log file of a session that includes content/text of the traffic/responses. What i have : Working silenium webdriver and browsermobproxy server log (*but without headers!).

browsermob-proxy working on localhost:8080/proxy/8081*

Partial Code:

bmp_path = "path-to-browsermob-proxy.bat"
server = Server(path=bmp_path)
server.start()
proxy_server = server.create_proxy()
proxy_server.new_har()
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server={}'.format(proxy_server.proxy))
browser = webdriver.Chrome("path-to-chromedriver.exe",chrome_options=chrome_options)
browser.get('www.demowebsite.com')

When printing:

pprint(proxy_server.har)

{"log":{"version":"1.2","creator":{"name":"BrowserMob Proxy","version":"2.1.4","comment":""},"pages":[{"id":"Page 0","startedDateTime":"2019-10-03T15:17:20.385+03:00","title":"Page 0","pageTimings":{"comment":""},"comment":""}],"entries":[],"comment":""}}

So far so good, Now here is the thing.

When i add any param to new_har like:

proxy_server.new_har(options={'captureHeaders': True})

Or:

proxy_server.new_har('test') # for ref param

Always get a 500 response from the server:

r = requests.put('%s/proxy/%s/har' % (self.host, self.port), payload)

Problem accessing /proxy/8081/har. Reason: Server Error

{JSONDecodeError}Expecting value: line 1 column 1 (char 0)

It looks like i can't make a request to the proxy server ? Thanks for helpers

imoshe avatar Oct 07 '19 10:10 imoshe

Same Quescion

temp.py:20: DeprecationWarning: use options instead of chrome_options driver = webdriver.Chrome(chrome_options=chrome_options) Traceback (most recent call last): File "temp.py", line 26, in json.dumps(proxy.har) File "/usr/local/anaconda3/lib/python3.7/site-packages/browsermobproxy/client.py", line 104, in har return r.json() File "/usr/local/anaconda3/lib/python3.7/site-packages/requests/models.py", line 897, in json return complexjson.loads(self.text, **kwargs) File "/usr/local/anaconda3/lib/python3.7/json/init.py", line 348, in loads return _default_decoder.decode(s) File "/usr/local/anaconda3/lib/python3.7/json/decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/local/anaconda3/lib/python3.7/json/decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

suochenxi avatar Apr 13 '20 09:04 suochenxi

Not sure if its still an issue but the following works for me in ruby. proxy.new_har(options={"capture_binary_content": "true", "capture_content": "true", "capture_headers": "true"})

Ankurg09 avatar Nov 15 '21 16:11 Ankurg09