Browsermob proxy how to make it work with selenium grid? [java]

1,406 views
Skip to first unread message

nvldk

unread,
Jul 6, 2016, 10:10:49 AM7/6/16
to BrowserMob Proxy

What I have in my code:

public BrowserMobProxy getProxy() throws UnknownHostException {
    if (proxy == null) {
        proxy = new BrowserMobProxyServer();
        proxy.start(0);
    }
    return proxy;

seleniumProxy = ClientUtil.createSeleniumProxy(getProxy());
caps.setCapability(CapabilityType.PROXY, seleniumProxy);

The problem is running on local its fine but running it on grid(either own or browserstack) it is not working. Is there any way how to make it work - proxy running on local and listening to remote driver?

I tried:

proxy.start(0, InetAddress.getLocalHost());

But without success.

Any ideas?

⇜Krishnan Mahadevan⇝

unread,
Jul 6, 2016, 10:28:14 AM7/6/16
to browserm...@googlegroups.com
Have you tried printing the contents of the seleniumProxy object and see what it shows [ IP and Port ] ?
The next thing you would have to do is, check if the network connectivity exists between the machine on which your node runs and your local machine (where your BMP runs).

With a browser stack grid I don't know how it would work because technically speaking you aren't on the same network. 

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

--

---
You received this message because you are subscribed to the Google Groups "BrowserMob Proxy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to browsermob-pro...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

nvldk

unread,
Jul 6, 2016, 10:48:57 AM7/6/16
to BrowserMob Proxy
Yes, I did and it shows my IP:port.

I tried my own selenium grid + standalone proxy both running on docker. Still without success.

I guess I`m missing something very basic.

Thanks.



Dne středa 6. července 2016 16:28:14 UTC+2 Krishnan napsal(a):

⇜Krishnan Mahadevan⇝

unread,
Jul 6, 2016, 10:50:17 AM7/6/16
to browserm...@googlegroups.com
You mean you are running the selenium grid on a different docker and BMP on a different docker ? 

Can you please help add a bit more context around your setup so that we can get a good idea on how your setup looks like ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

nvldk

unread,
Jul 6, 2016, 10:56:13 AM7/6/16
to BrowserMob Proxy
Yes, I have 3 docker containers -hub, node and browsermob proxy. Right now I`m searching for a solution. I do not insist on extra browsermob container. 

Dne středa 6. července 2016 16:50:17 UTC+2 Krishnan napsal(a):

je...@outlook.com

unread,
Jul 9, 2016, 5:53:27 PM7/9/16
to BrowserMob Proxy
BMP works with a Selenium Grid (I typically use it this way). Each request follows this path:

Selenium test -> Selenium Grid (via WebDriver) -> BMP (via browser's HTTP proxy settings) -> Internet

So you need to make sure that the BMP instance is reachable from the browser running on the Selenium Grid. This is true whether BMP is running in embedded mode in the JVM or in standalone in a separate process. Basically, you need to know the IP address and port of the server that BMP is listening on and pass that to the browser in the Selenium Proxy object, AND it must be possible to reach that server/port from the Selenium Grid.

If you're using a public Selenium Grid, it's almost guaranteed that browsers on the public grid won't be able to reach your BMP instance. You'll have to open up firewall rules to allow them to reach your BMP instance.

Docker adds an extra layer of complexity, since ports are not exposed by default, so you'll need to expose the port that BMP is listening on (again, true whether using embedded mode or running BMP in a separate process or separate container). You won't be able to use ClientUtil.createSeleniumProxy() to do this, but creating the Selenium Proxy object is trivial once you know the correct IP address and port (have a look at the source code for that method).

Hope that helps!
Jason

Sheripally Ramesh

unread,
Jan 10, 2020, 8:01:30 AM1/10/20
to BrowserMob Proxy
Hi Nvldk,

I need your help please.

I am new to selenium and BMP.

I have been assigned a task by my customer - to get network traffic on selenium grid(using java). Hub is running on windows 10.

I have few questions please.
1. Where can I get the BMP jar file. I have downloaed the BMP software but there are multiple folders/files …. I am not sure which is the jar file in that?
2. I got below code from net. Kindly let me know if the below code is correct to get data on selenium grid. 

Please help clarify.


Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
            
       
       ChromeOptions options = new ChromeOptions();   
        options.setExperimentalOption("useAutomationExtension", false);       
         DesiredCapabilities capabilities = DesiredCapabilities.chrome();
        capabilities.setCapability(ChromeOptions.CAPABILITY, options);
        capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
        options.merge(capabilities);
             options.addArguments("--start-maximized");
            
            
            
            try {
               String hostIp = Inet4Address.getLocalHost().getHostAddress();
               seleniumProxy.setHttpProxy(hostIp + ":" + proxy.getPort());
               seleniumProxy.setSslProxy(hostIp + ":" + proxy.getPort());
           } catch (UnknownHostException e) {
               e.printStackTrace();
           }
    
           
           proxy.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);
    
    
           try {
    
               proxy.newHar("AccessIT");
    
               driver.get("http://www.accessit.com");
               try {
                   Thread.sleep(10000);
               } catch (InterruptedException e) {
                   e.printStackTrace();
               }
    
               Har har = proxy.getHar();
    
               File harFile = new File("accessit.har");
               har.writeTo(harFile);
    
            } catch (IOException ioe) {
                ioe.printStackTrace();
            }
Reply all
Reply to author
Forward
0 new messages