CasperJS with Slimerjs - Xlib: extension "RANDR" missing on display ":99" - linux

I am trying to running Casperjs with Slimerjs
I Installed SlimerJS 0.10.2
I have installed Mozilla Firefox 45.5.1 (tried with 50 too)
I have installed CasperJS 1.1.3
I have installed xvfb 1.17.4
Running on Centos 6.8
When tried to run a casperjs+slimerjs from php I get:
Gecko error: it seems /usr/bin/firefox is not compatible with SlimerJS.
See Gecko version compatibility. If version is correct, launch slimerjs
with --debug=true to see Firefox error message
When I try to run a script from console with debug=true like:
/usr/local/bin/casperjs /tmp/casperjs-5cn484 --debug=true --engine=slimerjs
(I tried with xvfb-run too)
I get this error:
Xlib: extension "RANDR" missing on display ":99".
process 5588: D-Bus library appears to be incorrectly set up; failed to read machine uuid: Failed to open "/var/lib/dbus/machine-id": No such file or directory
See the manual page for dbus-uuidgen to correct this issue.
D-Bus not built with -rdynamic so unable to print a backtrace
Redirecting call to abort() to mozalloc_abort
/usr/lib/node_modules/slimerjs/src/slimerjs: line 167: 5588 Segmentation fault "$SLIMERJSLAUNCHER" -app "$SLIMERDIR/application.ini" $PROFILE -no-remote "$#"
if i run slimerjs --debug=true, I get:
Error: cannot open display: :1.1
Gecko error: it seems /usr/bin/firefox is not compatible with SlimerJS.
See Gecko version compatibility. If version is correct, launch slimerjs
with --debug=true to see Firefox error message
I already tried a lot of solution, like:
tried: Xvfb :1 -screen 0 1024x768x24 +extension RANDR & and export DISPLAY=:1 (with :99 too)
tried export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/
upgrade downgrade firefox version
check if there was fonts, there is one, so no problem
I don't know what I am trying anymore, some suggestions? : )

Anyway I get it running installing dbus package and with the comand:
dbus-uuidgen > /var/lib/dbus/machine-id
The Xlib: extension "RANDR" missing on display ":99" isn't a big issue...
from:
http://www.torkwrench.com/2011/12/16/d-bus-library-appears-to-be-incorrectly-set-up-failed-to-read-machine-uuid-failed-to-open-varlibdbusmachine-id/

Did you see this issue? Apparently you should:
Change the max version in src/application.ini
MaxVersion=45.*
I'm not sure about the xrandr error but it seems unrelated. Could be a result of experimentation or a red herring.
There's also a DBUS error that could be causing the subsequent segmentation fault.
I suggest you try to check it step by step:
see that firefox is working
X forwarding might help here, it would bring up the remote firefox window locally
make sure that firefox is working headless
you could generate an xvfb screenshot
check with slimerjs
check with your PHP wrapper script

Related

Install chrome driver on Amazon Linux 2 ARM

I am looking to install Chrome Driver (For my selenium project) on an Amazon Linux 2 (Arm 64).
I have done this on Ubuntu and seems pretty straight, it also seems straight on AL2 x86, like this script from Intoli but it 404 when looking for Chrome on ARM :(. So far I see Chrome is not available for ARM so I see the alternative is to use Chromium.
I tried installing it manually but it seems there is no compiled on Chromium downloads page for ARM.
Finally i found the Electron's unofficial webdrivers, which seem to be the answer, and after downloading, installing dependencies (libXcursor, libXfixes, libXdamage) and running it:
[ec2-user#scraping1 current]$ chromedriver
Starting ChromeDriver 100.0.4896.143 (6bf1afe83487405ea0aff37182f05e3db45559c2-refs/branch-heads/4951#{#831}) 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.
And run my project I get:
2.7.3 :004 > Selenium::WebDriver::Service.driver_path = "/usr/bin/chromedriver"
=> "/usr/bin/chromedriver"
session = Capybara::Session.new
Webdrivers::BrowserNotFound: Failed to find Chrome binary.
Which means i don't have Chrome installed, but then how to install it? I have seen this question which seems to be my same problem but it is unclear to me how to install Chromium; I see it is needed to download and use the chromedriver compiled for ARM64 which I have done already.

vscode on Ubuntu is unable to open windows

I'm having issues with vscode on Ubuntu running particular Python code (that seemingly relies on porting or connecting to an external application). The same code will run fine if I execute it directly from an Ubuntu terminal with the same env on the same machine.
Here's a couple of examples.
When I try to initiate vedo.plotter.Plotter() when running from vscode, I get this error:
ERROR: In /work/standalone-x64-build/VTK-source/Rendering/OpenGL2/vtkXOpenGLRenderWindow.cxx, line 1223
vtkXOpenGLRenderWindow (0x5587f7b42cf0): bad X server connection. DISPLAY=Aborted (core dumped)
If I run the same code directly in terminal, it runs fine, so this is an issue with the way vscode is configured, but I can't find any answers online. I've played with a few settings in vscode but with no success.
This seems to be an issue on all vscode installations I have running on Ubuntu (in this case 20.04). Here's the vscode info:
Version: 1.51.0
Commit: fcac248b077b55bae4ba5bab613fd6e9156c2f0c
Date: 2020-11-05T18:16:10.374Z
Electron: 9.3.3
Chrome: 83.0.4103.122
Node.js: 12.14.1
V8: 8.3.110.13-electron.0
OS: Linux x64 5.4.0-52-generic snap
Similarly, I'm unable to open up browser windows from vscode (for example plotly fig.show() and selenium driver = webdriver.Chrome(chromedriver) won't open browser windows. I get the following error with selenium:
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
(unknown error: DevToolsActivePort file doesn't exist)
Again, this works fine direct from the terminal and everything works fine if run from a Windows or Mac installed vscode, so this is specific to this Ubuntu install.
I'd really appreciate any help!
Jonny

Python 3 - selenium on xvfb-run- cannot process extension

I need to automate tasks to extract information from websites using the uBlock plugin with Chrome driver using the selenium module in Python 3.
I am running my code remotely without a GUI on the remote machine - for that I am using xvfb-run to simulate a desktop environment where Chrome launches with a specific window size.
The remote machine has the following Debian operating system:
uname -a
Linux mem 4.19.0-10-amd64 #1 SMP Debian 4.19.132-1 (2020-07-24) x86_64 GNU/Linux
These were the steps I took to configure my environment and code on the remote machine:
1 - To configure my environment, I installed this version of Google Chrome:
google-chrome --version
Google Chrome 86.0.4240.111
2 - Check the versions of Python 3 and selenium I installed:
python --version
Python 3.7.3
pip freeze
selenium==3.141.0
3 - Check the xvfb-run version:
apt-cache policy xvfb
2:1.20.4-1+deb10u1
4 - With these packages configured, I obtained the chromedriver_linux64.zip from this list (the version 86.0.4240.22 below is the most recent one that is the same major version of the installed google-chrome):
https://chromedriver.storage.googleapis.com/index.html
https://chromedriver.storage.googleapis.com/index.html?path=86.0.4240.22/
5 - To be able to use the uBlock extension of Chrome, I needed to install an extension that is able to produce a .crx archive file of other installed extensions.
For this, I used CRX Extractor/Downloader:
https://chrome.google.com/webstore/detail/crx-extractordownloader/ajkhmmldknmfjnmeedkbkkojgobmljda
6 - After using that extension, I got my ublock.crx file to test.
I managed to use the binary in chromedriver_linux64.zip without the extension to launch a Chrome instance and do some basic crawling.
But when I tried to use ublock.crx in my code, I got an exception.
The code was this:
This is the exception produced:
ublock.crx error
selenium.common.exceptions.SessionNotCreatedException: Message: session not
created: cannot process extension #1
from unknown error: cannot unzip
I am launching it from my program like this:
from selenium import webdriver
option = webdriver.ChromeOptions()
option.add_extension(ublock_crx_file_path)
driver = webdriver.Chrome(executable_path=driver_path, options=option)
I have made sure the path of ublock_crx_file_path is valid and points to the file I obtained from Chrome.
Hopefully someone can shed light on this?

WebDriverException: no chrome binary at /usr/bin/google-chrome-stable or chrome binary not found

I am executing selenium test via Jenkins server in AWS Ubuntu.
I was getting chrome binary not found error so I set chrome binary in my code.
System.setProperty("webdriver.chrome.driver","/var/lib/jenkins/.m2/repository/webdriver/chromedriver/linux64/83.0.4103.39/chromedriver");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("applicationCacheEnabled", true);
ChromeOptions options = new ChromeOptions();
options.merge(capabilities);
options.setBinary("/usr/bin/google-chrome-stable");
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--remote-debugging-port=9222");
options.addArguments("--disable-infobars");
options.addArguments("--disable-dev-shm-usage"); //Linux
options.addArguments("--disable-browser-side-navigation");
options.addArguments("--disable-gpu"); //Windows
options.addArguments("--disable-web-security");
driver = new ChromeDriver(options);
Then the error changed to: no chrome binary at /usr/bin/google-chrome-stable
Starting ChromeDriver 83.0.4103.39 (ccbf011cb2d2b19b506d844400483861342c20cd-refs/branch-heads/4103#{#416}) on port 14665
Only local connections are allowed.
ChromeDriver was started successfully.
INFO [main] (ControlCenter.java:108)- START
[ERROR] Tests run: 4, Failures: 1, Errors: 0, Skipped: 3, Time elapsed: 2.116 s <<< FAILURE! - in TestSuite
[ERROR] com.info.end2end.ExcelAccountToFusion.onTestSetup Time elapsed: 2.032 s <<< FAILURE!
org.openqa.selenium.WebDriverException:
**unknown error: no chrome binary at /usr/bin/google-chrome-stable**
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'jenkins-it02', ip: '10.113.0.187', os.name: 'Linux', os.arch: 'amd64', os.version: '5.3.0-1019-aws', java.version: '11.0.7'
Driver info: driver.version: ChromeDriver
This is how my usr/bin is:
And this is message when I try to launch browser in command line:
I tried the solution given by #DebanjanB at Cannot find Chrome binary with Selenium in Python for older versions of Google Chrome but no luck. Any help is much appreciated as I have spent 2 days on this already.
Not sure if setBinary() should be pointing to /usr/bin/google-chrome-stable.
As per the documentation in How To Install Google Chrome 78 On a RHEL/CentOS 7 and Fedora Linux to install and use the latest google-chrome using Yum you need to follow the sequence below:
Open the Terminal application. Grab 64bit Google Chrome installer.
Type the following command to download 64 bit version of Google Chrome:
wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
Install Google Chrome and its dependencies on a CentOS/RHEL, type:
sudo yum install ./google-chrome-stable_current_*.rpm
Start Google Chrome from the CLI:
google-chrome &
Outputs from yum command:
Finally, you need to use the following line to set the chrome binary:
options.setBinary("/usr/bin/google-chrome");
Additional Considerations
Ensure that:
Execute your #Test as non-root user.
Always invoke driver.quit() within tearDown(){} method to close & destroy the WebDriver and Web Client instances gracefully.
Reference
You can find a couple of relevant discussions in:
Cannot find Chrome binary with Selenium in Python for older versions of Google Chrome
I did not have the actual fix for this issue but I could get around my actual blocker by installing Chromium instead of Chrome. Difference I found is the installation directory of both.
I installed Chrome and whereis Google-Chrome-Stable gives:
qa_user#jenkins:~$ whereis google-chrome-stable google-chrome-stable: /usr/bin/google-chrome-stable /usr/share/man/man1/google-chrome-stable.1.gz
And qa_user#jenkins:~$ google-chrome-stable gives: google-chrome-stable: command not found
Now for Chromium:
qa_user#jenkins:~$ whereis chromium-browser gives: chromium-browser: /usr/bin/chromium-browser /usr/lib/chromium-browser /etc/chromium-browser /usr/share/chromium-browser /usr/share/man/man1/chromium-browser.1.gz
and qa_user#jenkins~$ chromium-browser [21304:21304:0607/135202.629230:ERROR:browser_main_loop.cc(1473)] Unable to open X display. Identifies and opens Chromium (X display issue can be solved by adding --headless option in actual Selenium code).
So I am gonna use Chromium instead of Chrome until I/Someone here find the fix for the actual Chrome issue here.
UPDATE:
After my below solution, I uninstalled Chromium and kept only Chrome for further testing. Surprisingly, chrome issue got fixed. I am able to run tests in Chrome now. Not sure how this is happening but I think it has something to do with dependency package that comes with Chrome.
I know this is strange but installing Chrome and Chromium and then uninstalling Chromium worked for me.

Running Flash Player on Headless Linux Server

Warning: I'm not that good at using Linux, so be easy on me.
I'm running a CentOS 6 x64 Server. I have a swf designed to generate complex images on command. I did a lot of searching, and the best answer I could find is install Xvfb and Flash Player to run the SWF.
So I installed Xvfb fine, and downloaded the standalone flash player debugger for Linux. I use
xvfb-run ./flashplayerdebugger screenapp.swf
to generate the image. Flash player debugger is designed for x86, and was throwing an error. I googled it, and found a page telling me to install the x86 dependencies. I did it, and the errors are gone. Unfortunately the swf doesn't seem to work on the server. For testing purposes it contacts a php file which creates a text file, so I know it's working, which works fine on my Windows computer for testing.
All it does is after I run the command is hang, after waiting a bit nothing still happens. I'm not sure if it's supposed to be like that, but it's not running the simple code I have on the swf to just load a URL
[root#ms1 ~]# xvfb-run ./flashplayerdebugger screenapp.swf
Xlib: extension "RANDR" missing on display ":99".
^Z
[3]+ Stopped xvfb-run ./flashplayerdebugger screenapp.swf
I'm no Linux expert, but the test SWF works fine on Windows, just can't get it to run on Linux. If the problem is flashplayerdebugger, how can I install the correct flash player?
Try this
xvfb-run +extension RANDR ./flashplayerdebugger screenapp.swf
Also, I found that its very useful that in Linux you can just copy-paste any console error or message by ctrl+shift+c (various for different consoles) and just google about it possible solutions.

Resources