AutomatedTester / browsermob-proxy-py

A python wrapper for Browsermob Proxy
http://oss.theautomatedtester.co.uk/browsermob-proxy-py
234 stars 104 forks source link

Firefox not use proxy #64

Open Negashev opened 7 years ago

Negashev commented 7 years ago

I run selenium hub with firefox and proxy browsermob by bwowk/browsermob-proxy

1) all in docker-compose.yml file

hub:
  image: selenium/hub
  ports:
    - 4444:4444
firefox:
  image: selenium/node-firefox
  links:
    - hub
    - proxy
proxy:
  image: bwowk/browsermob-proxy
  ports:
    - 58080:8080

2) Create a Dockerfile with pip install selenium browsermob-proxy and link hub and proxy

FROM python:3-alpine
RUN pip install selenium browsermob-proxy

3) in terminal write

from selenium import webdriver
from browsermobproxy import Client

proxyClient = Client("proxy:8080")

proxy = proxyClient.selenium_proxy()

caps = webdriver.DesiredCapabilities.FIREFOX.copy()
proxy.add_to_capabilities(caps)

driver = webdriver.Remote(command_executor='http://hub:4444/wd/hub', desired_capabilities=caps)

proxyClient.new_har()

driver.get('http://google.com')

for ent in proxyClient.har['log']['entries']:
    print(ent['request']['url'])

proxyClient.close()
driver.quit()

in debug i see that var caps have are proxy key and in proxy server i see that new proxy is registered 3 4

Result

But firefox does not use this proxy address. That is why i can not get logs.

proxyClient.har['log']['entries'] is null []

in docker image 5

tkuben commented 7 years ago

Hi @Negashev

I too had the same issue and came up with the following work around. The problem is that when you use browsermobproxy (bmp), any https requests go through the MITM with LittleProxy. This uses its own self signed certificate which is not trusted by your browser. So what I did was:

  1. Created a profile that I can utilize
  2. Opened up firefox using that profile and added the certificate as an authority by going to: Tools->Options->Advanced->Certificates->View Certificates button. Under Authorities tab, hit Import and find the: ca-certificate-rsa.cer file which can be found in your browsermob directory under ssl-support. Once you install the authority, any secure site you visit using the proxy will be fine.
profile = webdriver.FirefoxProfile(profile_directory=FIREFOX_PROFILE)
profile.set_proxy(self.proxy.selenium_proxy())
profile.accept_untrusted_certs = True
profile.assume_untrusted_cert_issuer = False
profile.update_preferences()
self.browser = webdriver.Firefox(firefox_profile=profile, proxy=self.proxy)

Hope this helps Cheers,

Thusjanthan Kubendranathan

frogfx commented 6 years ago

This is not working