debugging chrome remotely - doesn't open websocket - selenium

Im running chrome headless through chromedriver and selenium via python.
I've run into the following issue both on Mac and Linux.
Im starting chrome as follows:
if self.headless:
options.headless = True
options.add_argument("--headless")
if self.debug_port:
logging.info(f"Setting up remote debugging on port {self.debug_port}")
options.add_argument(f"--remote-debugging-port={self.debug_port}")
options.add_argument(f"--remote-debugging-address=0.0.0.0")
If I connect to http://localhost:9222 from another headed instance of chrome I can see the list of sessions and connect to it seamlessly. At which point i have a window opened up with a screencast of the remote session and the dev console.
Here's that successful example:
When I connect to http://192.168.1.194:9222 I get the list of sessions just fine and upon selecting one the dev console opens but it doesn't start the websocket connection to ws://192.168.1.194 so the screencast and remote debugging capabilities are not available.
Here's that failed example:
I've captured har files and uploaded them here if you want to take a look

Using the following steps I was able to debug remotely. However the screencast functionality did not work. Ultimately that's what I needed so this is only a 50% solution in my case.
So, as noted above in the comments, what's blocking remote debugging from working is that the chrome debugger links out to https://chrome-devtools-frontend.appspot.com/..... and passes a value of ws://192.168.1.194 for the websocket parameter. Any browser will inherently block this, based on it being mixed content - i.e: https + ws
What's needed here is to run the chrome dev tools frontend on a http server
and direct your chrome instance to that server instead of the appspot instance.
Solution Steps
1 Install depot_tools (pre-requisite for building)
https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.html#_setting_up
2 Checkout the devtools-frontend repo
https://github.com/ChromeDevTools/devtools-frontend/blob/master/docs/workflows.md#checking-out-source
3 Build chrome devtools frontend
https://github.com/ChromeDevTools/devtools-frontend/blob/master/docs/workflows.md#build
4 Start the devtools-frontend http server
https://github.com/ChromeDevTools/devtools-frontend/blob/master/docs/workflows.md#running-in-hosted-mode
5 Run 2 instances of chrome and use one to debug the other
5.1 Start first instance of chrome headless
...with remote debugging enabled. See the python way in the question above or do it from the command line with the same arguments
5.2 Start a second instance of chrome
...using a different user data dir --user-data-dir=<some-path>
5.3 Navigate to http://192.168.1.194:9222
Use whatever the IP address of the first chrome instance is and the port that you chose.
5.4 Create a link to the local dev server
The 2nd instance of chrome will now be showing you links to debug each of the open tabs of the 1st instance. However the links will still to go https://chrome-devtools-frontend.appspot.com/..... You'll need to copy n paste the link you want and replace the hostname with the hostname of the devtools frontend that you started in step 4
Walla!!
If you figure out how to get the screencast working please comment below! 🙏
N.B:
I also tried using the npm run server command in the devtools frontend but for some reason that server didn't work at all ¯\_(ツ)_/¯

Related

How to run test in IE browser using OxygenHQ?

I want to run a simple test using OxygenHQ, of opening wikipedia and then search for hello world. The script written is working fine for Chrome and Firefox but in case of IE mutiple windows are opening without the page and then it fails eventually.
Is there any way to fix this? I went through the docs provided at http://docs.oxygenhq.org/guide-web-intro.html but could not get a concrete answer on why this is only happening for IE. Here is a console output and screenshot for reference.
Console Output :
Initializing...
Starting iteration #1
UNKNOWN_ERROR - undefined: args[0].endsWith is not a function at line 1Test finished with status --> FAILED
Details:
Browser: Internet Explorer
Version: 11.535.18362.0
OS: Windows 10
This might be connected to your internet settings
make sure that the IE screen size is 100%
make sure all Internet options in Security Tab (Internet, Local Internet etc') are either with the Enable protected mode on or off (should be the same for all)
see picture
Have a look again at the Oxygen web site, it has had a major facelift and a lot of new content

Windows 10 - chromedriver.exe returns me Only local connections are allowed

when I try to run chromedriver.exe last version it returns me the same error message but always with another port:
Starting ChromeDriver 73.0.3683.20 (8e2b610813e167eee3619ac4ce6e42e3ec622017) on port 64862
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
I use Windows 10 Home. Where I can enable it to allow internet connections?
This is from a quote from the official chromedriver website. "By default, ChromeDriver only allows local connections. If you need to connect to it from a remote host, use --whitelisted-ips switch on the command line to specify a list of IP addresses that are allowed to connect to ChromeDriver."
http://chromedriver.chromium.org/security-considerations
In other words, Only local connections are allowed. is supposed to show when running chromedriver if not you want to run it from a remote host.
This error is getting because of Browser Version which you have in your local and chromdriver which you downloaded into the Project.
Cross check your downloaded chromedriver + Browser Version, if there is a deviation please download the one which match's the version you had.
Here is the Link - https://sites.google.com/a/chromium.org/chromedriver/
What you are seeing is not an error. It is an informational message.
When you run this driver, it will enable your scripts to access this and run commands on Google Chrome.
This can be done via scripts running in the local network (Only local connections are allowed.) or via scripts running on outside networks (All remote connections are allowed.). It is always safer to use the Local Connection option. By default your Chromedriver is accessible via port 9515.
See this answer if you wish to allow all connections instead of just local.
If your Chromedriver only shows the above three messages (as per the question), then there is a problem. It has to show a message like this, which says it started successfully.
Starting ChromeDriver 83.0.4103.39 (ccbf011cb2d2b19b506d844400483861342c20cd-refs/branch-heads/4103#{#416}) on port 9515
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Step 1: Check your browser version
Open Google Chrome.
Options --> Help --> About Google Chrome
My version is: Version 83.0.4103.61
Step 2: Compare versions of Chromedriver and Google Chrome
Both versions should start with the same number. My browser version is 83, hence, the chrome driver version should also be 83. If your versions mismatch, then you will see the following message. You will not see the line which says, ChromeDriver was started successfully..
Starting ChromeDriver 80.0.3987.106 (f68069574609230cf9b635cd784cfb1bf81bb53a-refs/branch-heads/3987#{#882}) on port 9515
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Step 3: Download the correct version of Chromedriver
Download the correct version that matches your browser version. Use this page for downloads. To set up this for windows, see this answer. Do step 2 again.
There is no need to have the same version of chromedriver and chrome, I just tried a different version of chromedriver, and the one which was a version older than my chrome worked! ( my chrome was version 91 and my chrome driver was version 90)
I have used selenium for a while and it does seem like it should show "Only local connections" when I'm using. I can do all the things I do normally on chrome if I would like to make selenium to click a youtube video it works. So let me ask you this what are you trying to do with selenium when using it? Have this "Only local connections" output stopped you from trying to do something when using selenium compared to browsing on chrome?
update
*Someone else had the same question here's the answer from there, note that the person who asked the same question as you didn't mark this answer as solved but should be so.

Chrome (and ONLY Chrome) Suddenly Can't Connect to Localhost Domains

Well this is odd. As of this morning, Chrome is responding with ERR_CONNECTION_REFUSED when it attempts to connect to web pages at various {subdomain}.localhost domains. Firefox and Safari both connect as normal. I am using Vagrant/Virtualbox running Debian and Apache. Chrome does connect to local domains which ARE NOT using localhost in the domain name. Wondering if chrome released some sort of local firewall?? But not seeing anything about that in release notes.
UPDATE: running curl {subdomain}.localhost in terminal gives me the output as expected (response from web server).
UPDATE 2: I did just find this: https://news.ycombinator.com/item?id=9210484 (Chrome team planning to block all access from browser to localhost wss) -- but I do not see that this was implemented yet.
The answer is in my second update. No more .localhost.
you can try using the port explicitly -> xxx.localhost:8080

How i launch a Google-Chrome Session from an SSH connection

Ey guys, im trying to use selenium/Google Chrome to automate some development and testing task. what i want to do is to avoid any X remote session or even VNC to the server, jsut let for example python launch my app that connects to selenium engine under Chrome Browser.
My problem is that of course when im on my ssh session if i try to launch google-chrome or even my selnium plugin i get browser_main_loop.cc(240)] Gtk: cannot open display .
there is anyway that i can send this command to an already opened X session and get the results back?
Thanks!

Selenium RC and Internet Explorer 7 with rspec for HTTPS and HTTP connections

We test our rails web application with rspec and use the selenium-client (gem version 1.2.18) API in our rspec tests to let selenium RC server (version 2.21.0) steer internet explorer 7 under AP to test our application.
This worked very well until we introduced HTTPS for our login and registration process. Now the user is redirected to the secure version of the login and registration form and afterwards redirected back to the unsecure HTTP site.
For our selenium tests to work with HTTPS and internet explorer 7 we are setting up the selenium driver with "*iexploreproxy" instead of "*iexplore" and use port 4444. We also installed the CyberVillans SSL Certificate as describe here http://blog.mogotest.com/2010/04/13/how-to-accept-self-signed-ssl-certificates-in-selenium/. We run selenium rc server with -trustALLSSLCertificates. This solved the self signed SSL Certificate issues (be aware that selenium RC > 2.21 does not work because of a bug which sets a wrong valid from date).
After that we received "Permission Denied" errors, when running our tests. We found out that this is because of the same origin problem described at http://wiki.openqa.org/display/SEL/Selenium+Core+FAQ under "Why do I get a Permission Denied error when accessing my website via HTTPS?". This problem can be solved by adjusting internet explorers 7 proxy settings and using localhost:4444 to route everything through the selenium RC server. It works, but the problem is that after every test run the proxy settings are reset.
My first question is: How is it possible to make those settings persistent in the internet explorer 7? I read about custom profiles for IE but I haven't found out how to set this up for rspec tests. I also read about a proxy.pac file, but googling for solution without success.
The next problem is that when running our tests we also run into "Access denied" errors by selenium. I have no idea how to solve these and why they occur. So my second question is: How do I get rid of those under the setup described.