[GH-ISSUE #3244] firefox silenium #2037

Closed
opened 2026-05-05 08:42:23 -06:00 by gitea-mirror · 17 comments
Owner

Originally created by @ddd7et on GitHub (Feb 24, 2020).
Original GitHub issue: https://github.com/netblue30/firejail/issues/3244

How to run a program silenium with firejail? I want to run Firefox with silenium inside python program.

Example, python file start.py
``

import selenium.webdriver as webdriver

driver = webdriver.Firefox("firejail /usr/bin/geckodriver")

``

Output: FileNotFoundError: [Errno 2] No such file or directory: 'firejail /usr/bin/geckodriver'

But I have geckodriver in /usr/bin folder.

Originally created by @ddd7et on GitHub (Feb 24, 2020). Original GitHub issue: https://github.com/netblue30/firejail/issues/3244 How to run a program silenium with firejail? I want to run Firefox with silenium inside python program. Example, python file start.py `` import selenium.webdriver as webdriver driver = webdriver.Firefox("firejail /usr/bin/geckodriver") `` Output: FileNotFoundError: [Errno 2] No such file or directory: 'firejail /usr/bin/geckodriver' But I have geckodriver in /usr/bin folder.
gitea-mirror 2026-05-05 08:42:23 -06:00
Author
Owner

@rusty-snake commented on GitHub (Feb 24, 2020):

But I have geckodriver in /usr/bin folder.

The error says that it can not find "firejail /usr/bin/geckodriver".

<!-- gh-comment-id:590273860 --> @rusty-snake commented on GitHub (Feb 24, 2020): > But I have geckodriver in /usr/bin folder. The error says that it can not find "firejail /usr/bin/geckodriver".
Author
Owner

@ddd7et commented on GitHub (Feb 24, 2020):

Ok,

driver = webdriver.Firefox("firejail --profile=firefox /usr/bin/geckodriver")
Output FileNotFoundError: [Errno 2] No such file or directory: 'firejail --profile=firefox /usr/bin/geckodriver'

I have Firefox Profile and you can see that I add folder /usr/bin folder. Also I added a folder /tmp (this folder is needed to selenium)


# Firejail profile for firefox
# This file is overwritten after every install/update
# Persistent local customizations
include /etc/firejail/firefox.local
# Persistent global definitions
include /etc/firejail/globals.local

noblacklist ${HOME}/.cache/mozilla
noblacklist ${HOME}/.config/okularpartrc
noblacklist ${HOME}/.config/okularrc
noblacklist ${HOME}/.config/qpdfview
noblacklist ${HOME}/.kde/share/apps/kget
noblacklist ${HOME}/.kde/share/apps/okular
noblacklist ${HOME}/.kde/share/config/kgetrc
noblacklist ${HOME}/.kde/share/config/okularpartrc
noblacklist ${HOME}/.kde/share/config/okularrc
noblacklist ${HOME}/.kde4/share/apps/kget
noblacklist ${HOME}/.kde4/share/apps/okular
noblacklist ${HOME}/.kde4/share/config/kgetrc
noblacklist ${HOME}/.kde4/share/config/okularpartrc
noblacklist ${HOME}/.kde4/share/config/okularrc
# noblacklist ${HOME}/.local/share/gnome-shell/extensions
noblacklist ${HOME}/.local/share/okular
noblacklist ${HOME}/.local/share/qpdfview
noblacklist ${HOME}/.mozilla
noblacklist ${HOME}/.pki
noblacklist /tmp 
noblacklist /usr/bin/
include /etc/firejail/disable-common.inc
include /etc/firejail/disable-devel.inc
include /etc/firejail/disable-programs.inc

mkdir ${HOME}/.cache/mozilla/firefox
mkdir ${HOME}/.mozilla
mkdir ${HOME}/.pki
whitelist ${DOWNLOADS}
whitelist /tmp
whitelist /usr/bin/
whitelist ${HOME}/.cache/gnome-mplayer/plugin
whitelist ${HOME}/.cache/mozilla/firefox
whitelist ${HOME}/.config/gnome-mplayer
whitelist ${HOME}/.config/okularpartrc
whitelist ${HOME}/.config/okularrc
whitelist ${HOME}/.config/pipelight-silverlight5.1
whitelist ${HOME}/.config/pipelight-widevine
whitelist ${HOME}/.config/qpdfview
whitelist ${HOME}/.kde/share/apps/kget
whitelist ${HOME}/.kde/share/apps/okular
whitelist ${HOME}/.kde/share/config/kgetrc
whitelist ${HOME}/.kde/share/config/okularpartrc
whitelist ${HOME}/.kde/share/config/okularrc
whitelist ${HOME}/.kde4/share/apps/kget
whitelist ${HOME}/.kde4/share/apps/okular
whitelist ${HOME}/.kde4/share/config/kgetrc
whitelist ${HOME}/.kde4/share/config/okularpartrc
whitelist ${HOME}/.kde4/share/config/okularrc
whitelist ${HOME}/.keysnail.js
whitelist ${HOME}/.lastpass
whitelist ${HOME}/.local/share/gnome-shell/extensions
whitelist ${HOME}/.local/share/okular
whitelist ${HOME}/.local/share/qpdfview
whitelist ${HOME}/.mozilla
whitelist ${HOME}/.pentadactyl
whitelist ${HOME}/.pentadactylrc
whitelist ${HOME}/.pki
whitelist ${HOME}/.vimperator
whitelist ${HOME}/.vimperatorrc
whitelist ${HOME}/.wine-pipelight
whitelist ${HOME}/.wine-pipelight64
whitelist ${HOME}/.zotero
whitelist ${HOME}/dwhelper
include /etc/firejail/whitelist-common.inc
include /etc/firejail/whitelist-var-common.inc

caps.drop all
# machine-id breaks pulse audio; it should work fine in setups where sound is not required
#machine-id
netfilter
nodvd
nogroups
nonewprivs
noroot
notv
protocol unix,inet,inet6,netlink
seccomp
shell none
tracelog

disable-mnt
# firefox requires a shell to launch on Arch.
# private-bin firefox,which,sh,dbus-launch,dbus-send,env,bash
private-dev
# private-etc below works fine on most distributions. There are some problems on CentOS.
# private-etc iceweasel,ca-certificates,ssl,machine-id,dconf,selinux,passwd,group,hostname,hosts,localtime,nsswitch.conf,resolv.conf,xdg,gtk-2.0,gtk-3.0,X11,pango,fonts,firefox,mime.types,mailcap,asound.conf,pulse
private-tmp

noexec ${HOME}
noexec /tmp

EDIT by @rusty-snake: code-block for profile.

<!-- gh-comment-id:590276307 --> @ddd7et commented on GitHub (Feb 24, 2020): Ok, `` driver = webdriver.Firefox("firejail --profile=firefox /usr/bin/geckodriver") `` Output FileNotFoundError: [Errno 2] No such file or directory: 'firejail --profile=firefox /usr/bin/geckodriver' I have Firefox Profile and you can see that I add folder /usr/bin folder. Also I added a folder /tmp (this folder is needed to selenium) ------------ ``` # Firejail profile for firefox # This file is overwritten after every install/update # Persistent local customizations include /etc/firejail/firefox.local # Persistent global definitions include /etc/firejail/globals.local noblacklist ${HOME}/.cache/mozilla noblacklist ${HOME}/.config/okularpartrc noblacklist ${HOME}/.config/okularrc noblacklist ${HOME}/.config/qpdfview noblacklist ${HOME}/.kde/share/apps/kget noblacklist ${HOME}/.kde/share/apps/okular noblacklist ${HOME}/.kde/share/config/kgetrc noblacklist ${HOME}/.kde/share/config/okularpartrc noblacklist ${HOME}/.kde/share/config/okularrc noblacklist ${HOME}/.kde4/share/apps/kget noblacklist ${HOME}/.kde4/share/apps/okular noblacklist ${HOME}/.kde4/share/config/kgetrc noblacklist ${HOME}/.kde4/share/config/okularpartrc noblacklist ${HOME}/.kde4/share/config/okularrc # noblacklist ${HOME}/.local/share/gnome-shell/extensions noblacklist ${HOME}/.local/share/okular noblacklist ${HOME}/.local/share/qpdfview noblacklist ${HOME}/.mozilla noblacklist ${HOME}/.pki noblacklist /tmp noblacklist /usr/bin/ include /etc/firejail/disable-common.inc include /etc/firejail/disable-devel.inc include /etc/firejail/disable-programs.inc mkdir ${HOME}/.cache/mozilla/firefox mkdir ${HOME}/.mozilla mkdir ${HOME}/.pki whitelist ${DOWNLOADS} whitelist /tmp whitelist /usr/bin/ whitelist ${HOME}/.cache/gnome-mplayer/plugin whitelist ${HOME}/.cache/mozilla/firefox whitelist ${HOME}/.config/gnome-mplayer whitelist ${HOME}/.config/okularpartrc whitelist ${HOME}/.config/okularrc whitelist ${HOME}/.config/pipelight-silverlight5.1 whitelist ${HOME}/.config/pipelight-widevine whitelist ${HOME}/.config/qpdfview whitelist ${HOME}/.kde/share/apps/kget whitelist ${HOME}/.kde/share/apps/okular whitelist ${HOME}/.kde/share/config/kgetrc whitelist ${HOME}/.kde/share/config/okularpartrc whitelist ${HOME}/.kde/share/config/okularrc whitelist ${HOME}/.kde4/share/apps/kget whitelist ${HOME}/.kde4/share/apps/okular whitelist ${HOME}/.kde4/share/config/kgetrc whitelist ${HOME}/.kde4/share/config/okularpartrc whitelist ${HOME}/.kde4/share/config/okularrc whitelist ${HOME}/.keysnail.js whitelist ${HOME}/.lastpass whitelist ${HOME}/.local/share/gnome-shell/extensions whitelist ${HOME}/.local/share/okular whitelist ${HOME}/.local/share/qpdfview whitelist ${HOME}/.mozilla whitelist ${HOME}/.pentadactyl whitelist ${HOME}/.pentadactylrc whitelist ${HOME}/.pki whitelist ${HOME}/.vimperator whitelist ${HOME}/.vimperatorrc whitelist ${HOME}/.wine-pipelight whitelist ${HOME}/.wine-pipelight64 whitelist ${HOME}/.zotero whitelist ${HOME}/dwhelper include /etc/firejail/whitelist-common.inc include /etc/firejail/whitelist-var-common.inc caps.drop all # machine-id breaks pulse audio; it should work fine in setups where sound is not required #machine-id netfilter nodvd nogroups nonewprivs noroot notv protocol unix,inet,inet6,netlink seccomp shell none tracelog disable-mnt # firefox requires a shell to launch on Arch. # private-bin firefox,which,sh,dbus-launch,dbus-send,env,bash private-dev # private-etc below works fine on most distributions. There are some problems on CentOS. # private-etc iceweasel,ca-certificates,ssl,machine-id,dconf,selinux,passwd,group,hostname,hosts,localtime,nsswitch.conf,resolv.conf,xdg,gtk-2.0,gtk-3.0,X11,pango,fonts,firefox,mime.types,mailcap,asound.conf,pulse private-tmp noexec ${HOME} noexec /tmp ``` --- EDIT by @rusty-snake: code-block for profile.
Author
Owner

@rusty-snake commented on GitHub (Feb 24, 2020):

Referring to https://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.firefox.webdriver the first argument is the firefox profile.

And /usr/bin is never blacklisted in the profile provided by firejail.

<!-- gh-comment-id:590276912 --> @rusty-snake commented on GitHub (Feb 24, 2020): Referring to https://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.firefox.webdriver the first argument is the firefox profile. And `/usr/bin` is never blacklisted in the profile provided by firejail.
Author
Owner

@rusty-snake commented on GitHub (Feb 24, 2020):

Because of you firefox.profile I assume that you have an firejail-version older than 0.9.60, there you can't use firejail --profile=firefox.

driver = webdriver.Firefox("firejail --profile=firefox /usr/bin/geckodriver")
Output FileNotFoundError: [Errno 2] No such file or directory: 'firejail --profile=firefox /usr/bin/geckodriver'

This is not a shell-command! It tries to open/create the file/directory firejail --profile=firefox /usr/bin/geckodriver and not to execute this.

<!-- gh-comment-id:590278710 --> @rusty-snake commented on GitHub (Feb 24, 2020): Because of you firefox.profile I assume that you have an firejail-version older than 0.9.60, there you can't use `firejail --profile=firefox`. > driver = webdriver.Firefox("firejail --profile=firefox /usr/bin/geckodriver") Output FileNotFoundError: [Errno 2] No such file or directory: 'firejail --profile=firefox /usr/bin/geckodriver' This is not a shell-command! It tries to open/create the file/directory `firejail --profile=firefox /usr/bin/geckodriver` and not to execute this.
Author
Owner

@rusty-snake commented on GitHub (Feb 24, 2020):

Maybe you need something like this:

firefox_binary = FirefoxBinary("firejail")
firefox_binary.add_command_line_options("--profile=/etc/firejail/firefox.profile")
firefox_binary.add_command_line_options("/usr/bin/geckodrive")
driver = Firefox(firefox_binary=firefox_binary)

https://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.firefox.firefox_binary
https://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.firefox.webdriver

<!-- gh-comment-id:590279051 --> @rusty-snake commented on GitHub (Feb 24, 2020): Maybe you need something like this: ```python firefox_binary = FirefoxBinary("firejail") firefox_binary.add_command_line_options("--profile=/etc/firejail/firefox.profile") firefox_binary.add_command_line_options("/usr/bin/geckodrive") driver = Firefox(firefox_binary=firefox_binary) ``` https://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.firefox.firefox_binary https://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.firefox.webdriver
Author
Owner

@ddd7et commented on GitHub (Feb 24, 2020):

start_browser.py file
``

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver import Firefox

firefox_binary = FirefoxBinary("firejail")
firefox_binary.add_command_line_options("--profile=/etc/firejail/firefox.profile")
firefox_binary.add_command_line_options("/usr/bin/geckodrive")
driver = webdriver.Firefox(firefox_binary=firefox_binary)

``

Traceback (most recent call last):
File "/home/mn/AKernel/Program/start_browser.py", line 32, in
driver = webdriver.Firefox(firefox_binary=firefox_binary)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/firefox/webdriver.py", line 174, in init
keep_alive=True)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in init
self.start_session(capabilities, browser_profile)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities

Process returned 1 (0x1) execution time : 1.343 s

<!-- gh-comment-id:590282083 --> @ddd7et commented on GitHub (Feb 24, 2020): start_browser.py file `` from selenium.webdriver.firefox.firefox_binary import FirefoxBinary from selenium.webdriver import Firefox firefox_binary = FirefoxBinary("firejail") firefox_binary.add_command_line_options("--profile=/etc/firejail/firefox.profile") firefox_binary.add_command_line_options("/usr/bin/geckodrive") driver = webdriver.Firefox(firefox_binary=firefox_binary) `` Traceback (most recent call last): File "/home/mn/AKernel/Program/start_browser.py", line 32, in <module> driver = webdriver.Firefox(firefox_binary=firefox_binary) File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__ keep_alive=True) File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__ self.start_session(capabilities, browser_profile) File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities Process returned 1 (0x1) execution time : 1.343 s
Author
Owner

@ddd7et commented on GitHub (Feb 24, 2020):

geckodriver.log: Error: invalid -version command line option

<!-- gh-comment-id:590295379 --> @ddd7et commented on GitHub (Feb 24, 2020): geckodriver.log: Error: invalid -version command line option
Author
Owner

@ddd7et commented on GitHub (Feb 25, 2020):

This is answer from Henrik Skupin

Note that firejail needs an argument when being called (firejail firefox), and I don't see how this would work with your code above, which doesn't adds that. What you would need is a wrapper script for Firefox which includes that command, and can be called via geckodriver.

<!-- gh-comment-id:590990941 --> @ddd7et commented on GitHub (Feb 25, 2020): This is answer from Henrik Skupin Note that firejail needs an argument when being called (firejail firefox), and I don't see how this would work with your code above, which doesn't adds that. What you would need is a wrapper script for Firefox which includes that command, and can be called via geckodriver.
Author
Owner

@matu3ba commented on GitHub (Feb 27, 2020):

@ddd7et Could be unrelated to firejail here or this.
This might help you tracking exactly what fails.

I would suggest you to step-wise comment in all capability drops (in the loaded profile file) to obtain the thing that does not work.
Does the program work without firejail?

<!-- gh-comment-id:592075905 --> @matu3ba commented on GitHub (Feb 27, 2020): @ddd7et Could be unrelated to firejail [here](https://stackoverflow.com/questions/47782650/selenium-common-exceptions-sessionnotcreatedexception-message-unable-to-find-a/47785513) [or this](https://stackoverflow.com/questions/43713445/selenium-unable-to-find-a-matching-set-of-capabilities-despite-driver-being-in). [This](https://stackoverflow.com/questions/383944/what-is-a-python-equivalent-of-phps-var-dump) might help you tracking exactly what fails. I would suggest you to step-wise comment in all capability drops (in the loaded profile file) to obtain the thing that does not work. Does the program work without firejail?
Author
Owner

@ghost commented on GitHub (Feb 27, 2020):

selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities

I think there might be some confusion here around the term capabilities. The above error refers to WebDriver capabilities (see here) and not to firejail's (Linux kernel) capabilities.

<!-- gh-comment-id:592172248 --> @ghost commented on GitHub (Feb 27, 2020): > selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities I think there might be some confusion here around the term `capabilities`. The above error refers to WebDriver capabilities (see [here]( https://developer.mozilla.org/en-US/docs/Web/WebDriver/Capabilities)) and not to firejail's (Linux kernel) capabilities.
Author
Owner

@rusty-snake commented on GitHub (Mar 14, 2020):

@ddd7et still need help?

<!-- gh-comment-id:599127192 --> @rusty-snake commented on GitHub (Mar 14, 2020): @ddd7et still need help?
Author
Owner

@ddd7et commented on GitHub (Mar 15, 2020):

Yes and no. Yes, because I did not solve problem. No, because I use silenium (firefox) without firejail, and this is normal. I can live without firejail. I use firefox with silenium as the main browser for myself, and I will do this until August 2020. In August 2020, I want to return to this topic and I will try to think about it again.

<!-- gh-comment-id:599249627 --> @ddd7et commented on GitHub (Mar 15, 2020): Yes and no. Yes, because I did not solve problem. No, because I use silenium (firefox) without firejail, and this is normal. I can live without firejail. I use firefox with silenium as the main browser for myself, and I will do this until August 2020. In August 2020, I want to return to this topic and I will try to think about it again.
Author
Owner

@ddd7et commented on GitHub (Mar 16, 2020):

@ddd7et Could be unrelated to firejail here or this.
This might help you tracking exactly what fails.

I would suggest you to step-wise comment in all capability drops (in the loaded profile file) to obtain the thing that does not work.
Does the program work without firejail?

Yes, the program works without firejail. Firefox with selenium webdriver is my main browser. I'm writing this post with firefox selenium without firejail.

<!-- gh-comment-id:599625654 --> @ddd7et commented on GitHub (Mar 16, 2020): > @ddd7et Could be unrelated to firejail [here](https://stackoverflow.com/questions/47782650/selenium-common-exceptions-sessionnotcreatedexception-message-unable-to-find-a/47785513) [or this](https://stackoverflow.com/questions/43713445/selenium-unable-to-find-a-matching-set-of-capabilities-despite-driver-being-in). > [This](https://stackoverflow.com/questions/383944/what-is-a-python-equivalent-of-phps-var-dump) might help you tracking exactly what fails. > > I would suggest you to step-wise comment in all capability drops (in the loaded profile file) to obtain the thing that does not work. > Does the program work without firejail? Yes, the program works without firejail. Firefox with selenium webdriver is my main browser. I'm writing this post with firefox selenium without firejail.
Author
Owner

@ghost commented on GitHub (Mar 16, 2020):

@ddd7et Can you post your firefox selenium python script here please. I happen to use geckodriver/curl to open URL's intercepted from other sandboxed applications in an already running, fully firejailed Firefox. IMHO that's easier than starting Firefox via the WebDriver protocol and have it firejailed at the same time. That being said, if I look at code examples in this thread, I don't see any webdriver capabilities being passed. What about something like:

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver import Firefox
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

firefox_binary = FirefoxBinary("firejail")
firefox_binary.add_command_line_options("--profile=/etc/firejail/firefox.profile")
firefox_binary.add_command_line_options("/usr/bin/geckodriver")
driver = webdriver.Firefox(firefox_binary=firefox_binary,
   desired_capabilities=DesiredCapabilities.FIREFOX)

But without showing us your script this is all just guess-work...

<!-- gh-comment-id:599667236 --> @ghost commented on GitHub (Mar 16, 2020): @ddd7et Can you post your firefox selenium python script here please. I happen to use geckodriver/curl to open URL's intercepted from other sandboxed applications in an _already running, fully firejailed_ Firefox. IMHO that's easier than starting Firefox via the WebDriver protocol **and** have it firejailed at the same time. That being said, if I look at code examples in this thread, I don't see any webdriver capabilities being passed. What about something like: ``` from selenium.webdriver.firefox.firefox_binary import FirefoxBinary from selenium.webdriver import Firefox from selenium.webdriver.common.desired_capabilities import DesiredCapabilities firefox_binary = FirefoxBinary("firejail") firefox_binary.add_command_line_options("--profile=/etc/firejail/firefox.profile") firefox_binary.add_command_line_options("/usr/bin/geckodriver") driver = webdriver.Firefox(firefox_binary=firefox_binary, desired_capabilities=DesiredCapabilities.FIREFOX) ``` But without showing us your script this is all just guess-work...
Author
Owner

@ddd7et commented on GitHub (Mar 16, 2020):

Thank your for your interest to this topic.

This is my script (You can see how I run my Firefox but my full program is much harder, it's a very simple example). So this is file Start_Firefox.py

from selenium.webdriver import Firefox,  FirefoxProfile
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
import os
import json
import time

class Browser:

    def __init__(self):

        profile = FirefoxProfile("/home/mn/.mozilla/firefox/nkm3c5cp.default-release")

        binary = FirefoxBinary('/home/mn/Downloads/Firefox2/Firefox/firefox/firefox')
        self.driver = Firefox(profile)#, firefox_binary=binary)

        self.url = self.driver.command_executor._url
        self.session_id = self.driver.session_id

    def get_driver(self):
        return self.driver

    def save_session(self):

        conf = {}
        conf["url"] = self.url
        conf["session_id"] = self.session_id

        mfile = os.path.join(os.path.dirname(os.path.realpath(__file__)), "conf_Firefox.json")

        with open(mfile, "w") as jsonFile:
            json.dump(conf, jsonFile, ensure_ascii=False,
                      default=str, indent=4, sort_keys=True)

driver = Browser()
driver.save_session()
browser = driver.get_driver()

while True:
    try:
        browser.switch_to.window(browser.window_handles[-1])
    except Exception:
       quit()
    time.sleep(300) // you can use not 300 but 3

And this works and I can run my Firefox without Firejail. I use this script to run my Firefox silenium as my main (default) browser. I don't use ordinary firefox without silenium.

My script (How I run this py file) (file run.sh)

#!/bin/bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
cd $DIR
/usr/bin/python3 $DIR/Start_Firefox.py

If I run your script:

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium import webdriver

firefox_binary = FirefoxBinary("firejail")
firefox_binary.add_command_line_options("--profile=/etc/firejail/firefox.profile")
firefox_binary.add_command_line_options("/usr/bin/geckodriver")
driver = webdriver.Firefox(firefox_binary=firefox_binary,
   desired_capabilities=DesiredCapabilities.FIREFOX)

I have the error:

Traceback (most recent call last):
File "/home/mn/Program//test.py", line 9, in
desired_capabilities=DesiredCapabilities.FIREFOX)
File "/home/mn/.virtualenvs/cat/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 174, in init
keep_alive=True)
File "/home/mn/.virtualenvs/cat/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in init
self.start_session(capabilities, browser_profile)
File "/home/mn/.virtualenvs/cat/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/home/mn/.virtualenvs/cat/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/mn/.virtualenvs/cat/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities

<!-- gh-comment-id:599714363 --> @ddd7et commented on GitHub (Mar 16, 2020): Thank your for your interest to this topic. This is my script (You can see how I run my Firefox but my full program is much harder, it's a very simple example). So this is file Start_Firefox.py from selenium.webdriver import Firefox, FirefoxProfile from selenium.webdriver.firefox.firefox_binary import FirefoxBinary import os import json import time class Browser: def __init__(self): profile = FirefoxProfile("/home/mn/.mozilla/firefox/nkm3c5cp.default-release") binary = FirefoxBinary('/home/mn/Downloads/Firefox2/Firefox/firefox/firefox') self.driver = Firefox(profile)#, firefox_binary=binary) self.url = self.driver.command_executor._url self.session_id = self.driver.session_id def get_driver(self): return self.driver def save_session(self): conf = {} conf["url"] = self.url conf["session_id"] = self.session_id mfile = os.path.join(os.path.dirname(os.path.realpath(__file__)), "conf_Firefox.json") with open(mfile, "w") as jsonFile: json.dump(conf, jsonFile, ensure_ascii=False, default=str, indent=4, sort_keys=True) driver = Browser() driver.save_session() browser = driver.get_driver() while True: try: browser.switch_to.window(browser.window_handles[-1]) except Exception: quit() time.sleep(300) // you can use not 300 but 3 And this works and I can run my Firefox without Firejail. I use this script to run my Firefox silenium as my main (default) browser. I don't use ordinary firefox without silenium. My script (How I run this py file) (file run.sh) #!/bin/bash DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" cd $DIR /usr/bin/python3 $DIR/Start_Firefox.py If I run your script: from selenium.webdriver.firefox.firefox_binary import FirefoxBinary from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from selenium import webdriver firefox_binary = FirefoxBinary("firejail") firefox_binary.add_command_line_options("--profile=/etc/firejail/firefox.profile") firefox_binary.add_command_line_options("/usr/bin/geckodriver") driver = webdriver.Firefox(firefox_binary=firefox_binary, desired_capabilities=DesiredCapabilities.FIREFOX) I have the error: Traceback (most recent call last): File "/home/mn/Program//test.py", line 9, in <module> desired_capabilities=DesiredCapabilities.FIREFOX) File "/home/mn/.virtualenvs/cat/lib/python3.6/site-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__ keep_alive=True) File "/home/mn/.virtualenvs/cat/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__ self.start_session(capabilities, browser_profile) File "/home/mn/.virtualenvs/cat/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/home/mn/.virtualenvs/cat/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/home/mn/.virtualenvs/cat/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities
Author
Owner

@ghost commented on GitHub (Mar 16, 2020):

...
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities

Hm, that makes sense now I look at it again:

...
firefox_binary = FirefoxBinary("firejail")
...

The selenium webdriver tries to obtain the needed capabilities from the firejail binary, which will never succeed obviously. My knowledge of selenium is very limited, as I said, I only use geckodriver to connect to a running Firefox instance- which is already firejailed - and open a URL. That's quite easy in comparison. I'll try putting together a wrapper script and report back here, but to be honest I don't see how to pass this capabilities hurdle.

<!-- gh-comment-id:599725818 --> @ghost commented on GitHub (Mar 16, 2020): > ... > selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities Hm, that makes sense now I look at it again: ``` ... firefox_binary = FirefoxBinary("firejail") ... ``` The selenium webdriver tries to obtain the needed capabilities from the firejail binary, which will never succeed obviously. My knowledge of selenium is very limited, as I said, I only use geckodriver to connect to a running Firefox instance- which is already firejailed - and open a URL. That's quite easy in comparison. I'll try putting together a wrapper script and report back here, but to be honest I don't see how to pass this capabilities hurdle.
Author
Owner

@rusty-snake commented on GitHub (May 6, 2020):

I'm closing here due to inactivity, please fell free to reopen if you have more questions.

<!-- gh-comment-id:624726166 --> @rusty-snake commented on GitHub (May 6, 2020): I'm closing here due to inactivity, please fell free to reopen if you have more questions.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/firejail#2037
No description provided.