Selenium cannot start the snap-packaged Firefox on Ubuntu
Your error
Your Firefox profile cannot be loaded. It may be missing or inaccessible2 more lines it can showFix it fast
Most common cause, 1 of 2geckodriver runs outside the snap and puts the profile in /tmp
Start the geckodriver that ships inside the Firefox snap, which shares the snap's filesystem.
from pathlib import Path
from selenium import webdriver
# option A: the snap's own driver
service = webdriver.FirefoxService(executable_path="/snap/bin/geckodriver")
# option B: keep your driver, move the profile
# root = Path.home() / "selenium-profiles"; root.mkdir(exist_ok=True)
# service = webdriver.FirefoxService(service_args=["--profile-root", str(root)])
driver = webdriver.Firefox(service=service)
print(driver.capabilities["browserVersion"])
driver.quit()Short answer
Your Firefox profile cannot be loaded. It may be missing or inaccessible appears when geckodriver runs outside the Firefox snap on Ubuntu 22.04 or later. It writes its temporary profile to /tmp, which the confined snap cannot see. Use /snap/bin/geckodriver, pass --profile-root with a non-hidden folder under $HOME, or install Mozilla's own Firefox build instead.
Which cause do you have?
Find out whether Firefox is a snap and which geckodriver Selenium is about to use. A snap Firefox with a geckodriver outside /snap/bin points to cause 1; a binary_location of /snap/bin/firefox or /usr/bin/firefox in your options points to cause 2.
file /usr/bin/firefox # "shell script" here means it hands off to the snap
snap list firefox
which -a geckodriver
grep -rn "binary_location" --include=*.py .Then find the line you see in this list and open its fix:
- 1geckodriver runs outside the snap and puts the profile in /tmp
A modal says the profile cannot be loaded and the test hangs, or session creation fails with Process unexpectedly closed with status 1; which geckodriver prints /usr/local/bin or a ~/.cache/selenium path - 2binary_location points at the snap launcher, not the Firefox program
The session fails at once with binary is not a Firefox executable, and the options set binary_location to /snap/bin/firefox or /usr/bin/firefox
What does the error look like?
Your Firefox profile cannot be loaded. It may be missing or inaccessibleProcess unexpectedly closed with status 1binary is not a Firefox executable
Cause 1 of 2
geckodriver runs outside the snap and puts the profile in /tmp
You seeA modal says the profile cannot be loaded and the test hangs, or session creation fails with Process unexpectedly closed with status 1; which geckodriver prints /usr/local/bin or a ~/.cache/selenium path
Check
The Firefox profile cannot be loaded error comes from snap confinement. geckodriver writes a fresh profile into the system temp folder before it launches Firefox, but the Firefox snap has a private /tmp and cannot read hidden folders such as ~/.cache, so the browser opens with no usable profile. Mozilla tracks this as an open geckodriver bug, and the unpatched 0.37.1 release is still affected.
readlink -f "$(which geckodriver)"Fix
Start the geckodriver that ships inside the Firefox snap, which shares the snap's filesystem. If you must keep a downloaded geckodriver, give it a profile root that both sides can open, such as a plain folder under your home directory. The third route is to remove the snap and install Firefox from Mozilla's download page.
from pathlib import Path
from selenium import webdriver
# option A: the snap's own driver
service = webdriver.FirefoxService(executable_path="/snap/bin/geckodriver")
# option B: keep your driver, move the profile
# root = Path.home() / "selenium-profiles"; root.mkdir(exist_ok=True)
# service = webdriver.FirefoxService(service_args=["--profile-root", str(root)])
driver = webdriver.Firefox(service=service)
print(driver.capabilities["browserVersion"])
driver.quit()Verify
Firefox opens without the profile dialog and the script prints the browser version.
python3 smoke_firefox.pyConfirmed by firefox-source-docs.mozilla.org
Cause 2 of 2
binary_location points at the snap launcher, not the Firefox program
You seeThe session fails at once with binary is not a Firefox executable, and the options set binary_location to /snap/bin/firefox or /usr/bin/firefox
Check
On Ubuntu, /usr/bin/firefox is a shell script that runs /snap/bin/firefox, and that launcher is not the Firefox executable geckodriver expects to start. The geckodriver usage notes warn that pointing binary_location at /snap/bin/firefox only gives the not-a-Firefox-executable error.
ls -l /snap/firefox/current/usr/lib/firefox/firefoxFix
Use the real program inside the snap, and pair it with /snap/bin/geckodriver. Mixing the inner binary with a driver from outside the snap brings back the profile problem from cause 1.
from selenium import webdriver
options = webdriver.FirefoxOptions()
options.binary_location = "/snap/firefox/current/usr/lib/firefox/firefox"
service = webdriver.FirefoxService(executable_path="/snap/bin/geckodriver")
driver = webdriver.Firefox(options=options, service=service)Verify
The session starts, and driver.capabilities reports the same version as snap list firefox.
snap list firefoxConfirmed by firefox-source-docs.mozilla.org
How do I stop it coming back?
- In Dockerfiles and CI images based on Ubuntu 22.04 or newer, decide on purpose between the snap with /snap/bin/geckodriver and Mozilla's own Firefox build, and write the choice into the image.
- Store the geckodriver path and the Firefox binary path side by side in one settings file, so a review sees both whenever one changes.
- Never point --profile-root at /tmp or a dot-folder; the snap cannot read either.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: stegnor.com, Menulo, ShopGo.