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.

oneself
  • 1,079
  • 3
  • 16
  • 33
  • 1
    If Firefox is your default browser, you can use `xdg-open`, which opens any file with its associated application. – AFH Oct 20 '14 at 19:23

5 Answers5

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.

scrat.squirrel
  • 303
  • 2
  • 10
Barmar
  • 2,341
  • 17
  • 22
  • 4
    Not sure why, but I get the same result with -new-tab/-new-window. – oneself Oct 20 '14 at 20:21
  • Maybe you have a preference setting that conflates them. – Barmar Oct 20 '14 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 '14 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 '14 at 23:38
  • 1
    careful with the long options: they start with two dashes, such as: --new-tab – scrat.squirrel Mar 01 '15 at 16:30
  • @woohoo Not according to https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options, it shows just a single dash. – Barmar Mar 01 '15 at 20:56
  • @Barmar: That's fine, they keep changing them... on Linux it works with two dashes as well... which _is_ the standard with long command-line parameters. BTW, revert back the edit to your answer, I still see two dashes there in the first line of text. – scrat.squirrel Mar 02 '15 at 17:06
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.

oneself
  • 1,079
  • 3
  • 16
  • 33
  • 6
    What is the init file you are referring to? Thanks. – Nabil Kadimi Oct 05 '15 at 08:57
  • 1
    Note that setting `export MOZ_NO_REMOTE=0` instead is a [wrong track](https://superuser.com/a/1359864/388856), since both lines are synonyms. I got messed up with that XD – iago-lito Sep 20 '18 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.

Stephen Rauch
  • 3,091
  • 10
  • 23
  • 26
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!

x10an14
  • 101
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.

RimaNari
  • 173
  • 1
  • 1
  • 6