Run Firefox Background under Linux

The long start up time of firefox is general, especially with many add-ons. Is there any way to run firefox as background in order to obtain faster start up speed? If under windows, I have no idea, but for linux, I have find a way to hide a window to achieve running a desktop application “background”.

xdotool is a tool designed for control gui under CLI. xdotool has a option windowunmap, which mean “unmap a window, make it no longer appear on your screen”.

$ xdotool windowunmap [WID]

WID is window’s ID, which can obtain from xdotool search. A example for hiding a firefox window as follow(You must open a window of firefox):

$ xdotool windowunmap $(xdotool search --onlyvisible --name firefox)

And then the window of firefox disappears, whereas the pid can be seen of command ps -aux |grep firefox.

However, if you set firefox as default web browser, and then click a url under other application, firefox will open with the HIDE WINDOW, rather than a new window. And then you close firefox, and you will find there is no firefox application running background.

There are two ways to solve the problem, the first one is use firefox --new-window to replace firefox as default web browser command, the second one is to write a shell script to make firefox restart and hide after the firefox PID disappears.

Script for firefox-deamon

  1. Add a script under ~/.config/autostart-scripts directory:
#!/usr/bin/env bash
SLEEP_TIME=120  # every 120 seconds to check the firefox PID
sleep 10        # firefox will autostart after 10 seconds
while true;do
    is_waterfox=$(pgrep -u ${USER} ${BIN})
    if [ "${is_waterfox}"x  == x ];then
        #echo $(date +%R) Begin to make waterfox background
        nice -n 10 ${BIN}  1>/dev/null 2>&1 &
        while true
            wid=$(xdotool search --onlyvisible --name ${BIN});
            if [ ${wid}x != ''x ];then
                xdotool windowunmap ${wid};
    sleep ${SLEEP_TIME};
  1. Use firefox --new-window as default web browser.
This entry was posted in LINUX, 软件安装 and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.