How does Firefox discover a running instance to connect to?

In Linux, if I run Firefox as the current user that also runs the gui, and Firefox is already loaded, it simply opens a new window.

If I run Firefox via ‘pkexec --user username firefox’, the first run of it starts a new Firefox instance, as expected. However, if I run the same command again, it is unable to find the instance it previously created. Instead it gives the error: “Firefox is already running, but is not responding. To use Firefox, you must first close the existing Firefox process, restart your device, or use a different profile. For some reason, Firefox is unable to connect to the existing instance.”
What prevents Firefox from finding its running instance? Or, how does Firefox determine the current running instance? How could I provide it the details needed to find the running instance, as it does when run a second time as the main gui user?

1 Like

In case anyone ever has the same issue, I will share what solved it for me. By inspecting the environment variables available to Firefox, it seems that at the very least, Firefox needs XDG_RUNTIME_DIR set to the appropriate target. On Arch systems, that is /run/user/userid, and it is likely similar across Linux systems. Additionally, DBUS_SESSION_BUS_ADDRESS must be set to empty or unset, or it should point to the D-Bus address used by the already running Firefox instance. My speculation is that if it is set to something else, Firefox tries to run the instance on that D-Bus session address, but then finds the Firefox profile locked because it is already running on another D-Bus session address.