bonigarcia/webdrivermanager

launching browsers from/on restricted containers such as flatpak

adrian-herscu opened this issue · 4 comments

Description of the problem:
In continuation of #1000.

The library tries to launch the browser via /usr/bin/google-chrome, which fails if the automation process runs in a Flatpak container, or if the browser itself runs in a Flatpak container.

Executables from /usr/bin should be launched via flatpak-spawn --host <executable> <args> -- see
https://docs.flatpak.org/en/latest/flatpak-command-reference.html#flatpak-spawn

Another way would be to add host-os to available filesystems, which maps /usr/bin to /run/host -- see
https://docs.flatpak.org/en/latest/sandbox-permissions.html#filesystem-access
and https://docs.flatpak.org/en/latest/sandbox-permissions.html#reserved-paths

Even if the automation itself does not run in a Flatpak container, but the browser does, then it should be launched via flatpak run <app-id> (the app-id for Google Chrome would be com.google.Chrome).

There are Linux systems in which system's files, including those under /usr/bin directory are read-only -- see https://docs.fedoraproject.org/en-US/fedora-silverblue/technical-information/#filesystem-layout; hence, impossible to add a shim file.

All cases require some option to specify either the path or other executable -- is there something like this?

Browser and version:
N/R

Operating system and architecture:
Linux

Selenium version:
N/R

WebDriverManager version:
5.7.0

WebDriverManager call:
N/R

WebDriverManager traces:

Using WebDriverManager 5.7.0
There was a problem executing command </usr/bin/google-chrome --version> on the shell: Cannot run program "/usr/bin/google-chrome" (in directory "."): error=2, No such file or directory

Digged a bit and found commands.properties:

command.chrome.linux.01=google-chrome --version

this is loaded in VersionDetector and somewhere prepended with /usr/bin.

This should be customizable.

Any suggestion about how to override the default behavior?

You can use the method browserVersionDetectionCommand() to use a custom path for your browser

WebDriverManager.chromedriver().browserVersionDetectionCommand("/path/to/browser --version").setup();

See example.

Followed your suggestion and added somewhere in my code:

                    webDriverManager.browserVersionDetectionCommand(
                        "flatpak run com.google.Chrome");

Tested it in a bash shell as flatpak run com.google.Chrome --version
and it returns:

[0607/232449.452209:WARNING:chrome_main_linux.cc(80)] Read channel stable from /app/extra/CHROME_VERSION_EXTRA
Google Chrome 125.0.6422.141 

Didn't work :( The logs:

WebDriverManager - Using WebDriverManager 5.7.0
Shell - Running command on the shell: ['flatpak run, com.google.Chrome']
Shell - There was a problem executing command <flatpak run com.google.Chrome> on the shell: Cannot run program "flatpak run" (in directory "."): error=2, No such file or directory

I believe the command should contain the --version:

webDriverManager.browserVersionDetectionCommand("flatpak run com.google.Chrome --version");