wkeeling / selenium-wire

Extends Selenium's Python bindings to give you the ability to inspect requests made by the browser.
MIT License
1.9k stars 254 forks source link

No internet connection problem #247

Closed bublik007 closed 3 years ago

bublik007 commented 3 years ago

Hello guys,

I am experiencing a problem with selenium-wire. Once a chrome window is open, there is no internet connection in that window. All the outcoming requests are marked with red. Even if I manually (not through the python code) click on a link in the window, it will not be loaded. Importantly, if I initiate a request through the python code, e.g. by clicking (through the code) a button on the UI that generates a request, the request will go through. If I run my program using selenium, the issue is not appearing. I am not using any proxy.

The problem reproduces with a rather simple code:

from seleniumwire import webdriver

driver = webdriver.Chrome('\chromedriver.exe') driver.get('http://www.google.com/');

time.sleep(10)

Chrome: Version 89.0.4389.90 (latest) Windows: 10 Selenium-wire: latest Selenium: latest Python: 3.9

Any hints? Am I missing anything? I have seen a similar thread, but it is dedicated to running the python program as exe. I am running my code simply as a python script.

Thank you!

wkeeling commented 3 years ago

Thanks for raising this.

Selenium Wire works by temporarily redirecting browser traffic through an internal proxy server that gets started in the background. It uses this proxy server to intercept and capture requests. If Selenium Wire stops but the browser is left open, the browser won't work because it will try and send requests to the proxy server, but the proxy server won't be listening.

With the issue you're seeing, is Selenium Wire running when Chrome has the problems with the requests? It sounds as though Selenium Wire may have stopped (and so proxy server stopped) and so Chrome won't be able to make any requests? If Selenium Wire has died the script output may indicate why. Do you see any traceback or error message in the script output?

bublik007 commented 3 years ago

Hey,

thank you very much for the explanation.

Yes, you are totally right. The reason for requests not passing through was either that the script has crashed or finished its work. There were no problems in the selenium-wire workflow, it was all in my code

It might be a good idea though to drop a line to the console that the proxy has stopped listening for requests. Or mention it in your project description where you describe the usage of proxy.

Thank you again for the help.

wkeeling commented 3 years ago

Thanks - and good point about adding a console message. I'll look at adding something.