11

I would like to open a URL from the command line and have this open as a new tab or window in an already running and responding instance of Firefox. I'm using Debian's Sid branch. If I do the following:

In term 1:

$ firefox

In term 2:

$ firefox 'http://www.google.com'

Update: I've also tried -new-tab and -new-window, but I get the same result.

$ firefox -new-tab 'http://www.google.com'

I get the message:

Firefox is already running, but is not responding. To open a new window, 
you must first close the existing Firefox process, or restart your system.

This has been discussed before (e.g. here and here), however, I do not want to kill the existing instance of Firefox (it's doing just fine) and I don't want to use a different profile. This works seamlessly with Google Chrome.

1
  • 1
    If Firefox is your default browser, you can use xdg-open, which opens any file with its associated application.
    – AFH
    Oct 20, 2014 at 19:23

5 Answers 5

7

Use the --new-window or --new-tab command line options:

firefox --new-window 'http://www.google.com'
firefox --new-tab 'http://www.google.com'

See https://superuser.com/questions/699127/firefox-command-line-arguments/699128#699128 and Mozilla documentation

NOTE: firefox has switched to dash-dash -- style for the command line options.

7
  • 4
    Not sure why, but I get the same result with -new-tab/-new-window.
    – oneself
    Oct 20, 2014 at 20:21
  • Maybe you have a preference setting that conflates them.
    – Barmar
    Oct 20, 2014 at 20:22
  • 1
    I tried moving the ~/.mozilla dir out of the way and have Firefox recreate the default config. Same behavior. Are there any other settings that might influence this behavior?
    – oneself
    Oct 20, 2014 at 23:32
  • I think I discovered the culprit. I have MOZ_NO_REMOTE=1 set in my init file. Removing this fixed the problem. Thanks for your help.
    – oneself
    Oct 20, 2014 at 23:38
  • 1
    careful with the long options: they start with two dashes, such as: --new-tab Mar 1, 2015 at 16:30
3

I have the following line in my init file:

export MOZ_NO_REMOTE=1

This effectively prevents Firefox from doing exactly what I was trying to do. Removing this fixed the problem.

2
  • 6
    What is the init file you are referring to? Thanks. Oct 5, 2015 at 8:57
  • 1
    Note that setting export MOZ_NO_REMOTE=0 instead is a wrong track, since both lines are synonyms. I got messed up with that XD
    – iago-lito
    Sep 20, 2018 at 11:38
1

Create a file LaunchFireFox.sh with the line below:

xargs -a ff_url.txt firefox -new-tab "$line"

In a separate file ff_url.txt:

http://www.google.com

and any additional web pages.

0

For those of us using Wayland

This symptom might be due to wayland/xwayland issues (firefox's buglist).

What worked for me:

I'm running Sway, with MOZ_ENABLE_WAYLAND=1 set, and added the below to ~/.config/environment.d/<my-sway-config>.conf:

MOZ_DBUS_REMOTE=1

The above is equivalent to running the below inside a bash shell:

export MOZ_DBUS_REMOTE=1
firefox

Thereafter, all links clicked in other programs opened up in Firefox without issues. As expected. Thanks to Martin Stransky for getting me on the correct track!

0

If you want a new tab to open without a URL known yet, then firefox --new-tab (i.e. omitting a URL) will open a new window, which is probably not the desired behavior. Instead, use the following to open a new tab in the existing window (with the cursor set to the URL bar, so that you can enter your prompt right away):

firefox --new-tab about:newtab

This is a good command to use for a system-wide hotkey.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .