Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Next.js and React

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 show

Fix it fast

Most common cause, 1 of 2

geckodriver 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.

Fix
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()
Did this fix it?
Full steps for this cause: check, fix, verify

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.

  • Applies to Ubuntu 22.04 and 24.04 with the Firefox snap, Firefox 160, geckodriver 0.37.1, Selenium 4.53 for Python
  • Updated
  • By Maaz Zindani, Senior Software Engineer

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.

Run this first
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:

  1. 1geckodriver runs outside the snap and puts the profile in /tmpA 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
  2. 2binary_location points at the snap launcher, not the Firefox programThe 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 inaccessible
  • Process unexpectedly closed with status 1
  • binary 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.

Check
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.

Fix
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.

Verify
python3 smoke_firefox.py

Confirmed by firefox-source-docs.mozilla.org

Did this fix it?

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.

Check
ls -l /snap/firefox/current/usr/lib/firefox/firefox

Fix

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.

Fix
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.

Verify
snap list firefox

Confirmed by firefox-source-docs.mozilla.org

Did this fix it?

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.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.