Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

My problem with Firefox is that a new Firefox windows can only be launched from the same environment (or only from a child process?) from which the first window has been started. Even the same user who started FF cannot launch a new window from a new shell. That constantly interferes with my workflow.

Example: Say firefox has been started from the Destop already and now I want to start a new Firefox window from a root terminal:

    su desktopuser firefox
It does not work. It gives me "Firefox is already running, but is not responding.".


Why are you using root terminals in the first place? This has always been considered poor security practice. Consequently, your workflow is a very peculiar one, and while you personally might feel inconvenience, I don’t think that this frustrates many other Firefox users out there.


He's using 'su' to switch to desktopuser, that's not necessarily, and quite likely not, an account with root privileges. 'su' stands for 'switch user', it's not just to become root.


He uses the term “root terminal”, he writes “Start a root terminal (or a normal one and then ‘sudo su’)”, and he says he only has a single user. One will naturally assume the worst, and in spite of repeatedly posting here he hasn’t exactly made much sense about his workflow and needs beyond launching the browser.


You're right, I missed the root terminal part.


Correct.

I use a script in a root terminal to control a lot of my workflow. One thing is that I start browser windows from it when needed. I start them with

    sudo -u desktopuser chromium example.com
Because

    sudo -u desktopuser firefox example.com
does not work.

I thought that is relevant to the question "Why bother with Chrome".

desktopuser of course is the normal user which would also start Firefox if I did it via the Desktop gui.


Curious what use case you are looking at for over here? I don't want to make any assumptions. I'm wondering if what you are looking for might be covered by the functionality of tab containers.


I wrote a command line tool which tells me "Now look at the following page" and opens it a browser window with the url.

Works with Chrome, but not with Firefox.


Mac or Linux? I think on Mac "open" should Just Work, AFAIK


Linux


xdg-open <URL>

Works for me..


That would open the url in the default browser (Chromium for me) with the current user (root for me).

The task at hand is to open it in firefox with the desktop user.


Just use `--new-window` and it will work just fine :).


If you create a new profile for the different user, you can start a second session:

firefox -new-instance -P "Another Profile"


I don't have (nor want) multiple users.

I just want to open a new window for my one user.


So what's wrong with Super+N? I'm struggling to see the need for a completely new browser instance when you only want another window.


He doesn't want a completely new browser instance, he wants Firefox to open another window but depending on its mood Firefox refuses to do this.

Chrome can do this just fine btw.

Running Firefox from the command line isn't an obscure thing either, clicking a link on other apps like Signal or Telegram also use this method to spawn new tabs/windows. And depending on how you executed the first instance, you run into problems with clicking links on other apps as well.

I pretty much need to open Firefox first before clicking links on other apps, because otherwise I can't run Firefox normally later without killing the process.


No. Sorry. I have a list of complaints with Firefox but this is clearly user error. I do this literally every day for a decade or more. It works fine. It particularly helps to not unnecessarily use things that can affect the env like launching a browser with su. In fact I can I think it a list of things that could go wrong with that.


Yes, sorry. This is a Firefox bug and not user error.

On my Linux system, this works with any other browser I try. It only fails with Firefox. If this is user error, it seems every other browser handles user errors much better.

- Firefox: First window is open, running `firefox URL` from the other terminal hangs for 15-20 seconds and then shows the popup "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.". No new tabs or windows are spawned.

- Chromium: First window is open, running a `chromium URL` command from the other terminal opens a new tab on the existing window.

- Microsoft Edge: First window is open, running a `microsoft-edge-stable URL` command from the other terminal opens a new tab on the existing window.

- Ladybird: First window is open, running `ladybird` in the other terminal opens a new ladybird window.

- Emacs/eww: First window is open, running `emacs --eval '(eww "example.com")'` on another terminal opens a new browser window.

- Netsurf: First window is open, running `netsurf URL` from the other terminal opens a new netsurf window.

- Dillo: First window is open, running `dillo URL` from the other terminal opens a new dillo window.

- Links/XLinks: First window is open, running `xlinks -G URL` from the other terminal opens a new links window.

You can see a clear pattern. Got any other browsers that refuse to run with a message like that? Or is this not a fault of Firefox, and something super extra that everything from other mainstream browsers to more obscure ones somehow handle for the user?


I have never had Firefox do this. I've used all 3 major OS types in the last 5 years and Firefox on all of them. New windows open, no muss no fuss.

>I pretty much need to open Firefox first before clicking links on other apps, because otherwise I can't run Firefox normally later without killing the process.

The only way I imagine this happening is if one doesn't save the browser session between launches, maybe? I've had "cold start" link opens and it just adds another tab to my existing pinned tabs/open tabs/etc.

Everyone has different workflows I suppose.


Exactly.

It seems to be some magic Firefox puts somewhere (In the environment?) that prevents it to launch a new window from a fresh terminal that is not inherited from the same parent that launched the first window.


At least on Windows, other processes launching web pages involves launching a browser process with the URL as a parameter.

I used to get the "firefox not responding" all the time on Windows as well, though it has gotten a lot better not long ago.



Can you do it in an alternate version such as the developers edition?


I don't want to install multiple browser versions.

I just want to launch a new browser window.

This does not work:

    sudo -u normaluser firefox example.com
So I do:

    sudo -u normaluser chromium example.com
I thought that was relevant to the question "Why bother with Chrome".


To make this work you need to set the XDG_RUNTIME_DIR environment variable to the same value it has in the environment Firefox is running in. For example:

    sudo -u desktopuser XDG_RUNTIME_DIR=/run/user/1000 firefox --new-window


Please try this for yourself. It does not work. Gives the same "Firefox is already running, but is not responding." dialog.


I did try it. It even works from a different VT directly logged in as root if I also specify DISPLAY:

    sudo -u desktopuser XDG_RUNTIME_DIR=/run/user/1000 DISPLAY=:0.0 firefox --new-window
If I now switch back to the VT running my desktop, a new Firefox window has opened.

Maybe your root terminal has other environment variables set that break it? A different DBUS session maybe?


Oh wow, you were right! This solves it:

    sudo -u desktopuser XDG_RUNTIME_DIR=/run/user/1000 firefox
Sorry for messing it up the first time I tried!

Man, you solved it!!

Thanks a 1000 times!


No problem! Glad it works now.


Use keypirinha [1]. You can type "fir.." hit enter, a firefox window opens. Do it again, and a new firefox window opens.

[1]: https://keypirinha.com/


I believe --no-remote should get around that if using a separate profile doesn't. Of course, you should ensure the distinct processes are not using the same config/cache files.


Maybe you need to set the DISPLAY env var? Maybe it tries to contact the app via dbus and fails for some reason?

I'm quite sure this should work, and you just need to set some env var or so.


You can easily try jourself. 1) Have Firefox open 2) Start a root terminal (or a normal one and then "sudo su" 3) su normaluser firefox

It will refuse to start.


Did you try what I said? I'm pretty sure you just need to set some env vars right. (Not exactly sure which though. But some Googling should help, e.g. maybe how to setup dbus this way.)


Can’t you use -P for that kind of case?


I have very recently begun to see this bug; A workaround is that if you start a new Firefox from a shell on your desktop, then running “firefox” from a shell, even a different shell window, will work fine. I haven’t been able to find out why.


Yes, that is exactly what I am experiencing.

You cannot start FF from the Desktop and then start new windows from a shell.

Unless that shell was directly started from the desktop.

So it must have something to do with the environment or process tree.


I found what I think was the problem for me: From the desktop, I was starting Firefox with the “--no-remote” option. If I remove that option, then it works. I did not use that option when starting in a terminal, but if I do, then the same problem appears.


I am probably not understand your use-case correctly but there's a `--new-window` flag on the firefox binary. You can use that to open new windows under the same profile.


You can easily try jourself. 1) Have Firefox open 2) Start a root terminal (or a normal one and then "sudo su" 3) sudo -u normaluser firefox --new-window example.com

It will refuse to start.


Erm.... that is a completely different problem.

Do the following: sudo -EHs su, then as root sudo -EH -u {username} firefox --new-window

I'll leave to you the exercise of learning what the flags do, and implicitly why it fails in your case.


this works for me

env -i DISPLAY=$DISPLAY DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS firefox

this doesn't, it gives me the "Firefox is already running, but is not responding." message

env -i DISPLAY=$DISPLAY firefox


I'm not sure what you mean. What I try to achieve is start a new firefox window (for the normal user) from a root terminal. So part of the command has to be "sudo -u normaluser" or "su -l normaluser" or something.


You have to pass those environment variables to Firefox through sudo.

sudo has a --preserve-env=list option but you must know the value for DBUS_SESSION_BUS_ADDRESS. That's usually

  unix:path=/run/user/1000/bus
where 1000 is the id of the user Firefox is running for. Your root console could have no DBUS_SESSION_BUS_ADDRESS or have a different value for it.

To be 100% sure of the value, as you are root you could look into the environment of one of the running Firefox processes. Or wrap Firefox in a script that echoes that variable to a file before starting the browser.


Assuming it is "unix:path=/run/user/1000/bus", what would be the command to start Firefox as the normaluser with that setting?


I didn't test it but probably

  DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus \
  DISPLAY=:1 \
  sudo -H -u normaluser \
    --preserve-env=DBUS_SESSION_BUS_ADDRESS,DISPLAY \
  firefox
I'd add -H to the options of sudo to make it set the home to normaluser's one.

I assumed that your DISPLAY is :1, which is what my Debian has set for me. That's another variable that you could read from the environment of Firefox.

You might have to pass/preserve other environment variables to make Firefox work.


Whe don't you test it? It takes less time than to guess and have a back and forth via HN comments.


The parent gave all information which should help you in figuring it out by yourself now. The message it, it should work with the right env vars, and you have multiple example env vars to check for (DBUS related, DISPLAY, etc) and Google for. This is your work now.

(You could also test the extreme case: Just copy all the env vars.)


Because this is not a support forum or a stack exchange. I give the idea, then all the test and debugging is for who has to actually make the code work.


pass a URL!

su desktopuser

firefox about:blank




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: