4

I shut down Firefox at night by running killall -s SIGTERM firefox via cron, in order to apply the package manager and browser addon updates. Unfortunately each time when the browser is (manually) restarted, a 'restore session' tab about:sessionrestore is opened, obviously indicating that Firefox doesn't consider this as a clean exit. I'm relying on the 'delete cookies and site data when Firefox is closed' feature (with some domain exceptions) which supposedly has the potential to misbehave when the Firefox processes are killed.

The session data in the profile folders in ~/.mozilla/firefox/ does contain some private data and bloats my backups (not necessarily easy to filter out). rsync has to some degree reported that specific files in the directory have been changed during the transfer. I rotate between several Firefox profiles on two or more workspaces and closing each manually borders on nonfeasible.

The Mozilla documentation doesn't mention any such feature. A related question about Google Chrome (/ Chromium).


Any Wayland-friendly solutions (including, potentially, Selenium and some sensible macros) are also accepted.

4
  • 1
    According to bugzilla.mozilla.org/show_bug.cgi?id=336193#c73 there used to be a way years ago, but not any more.
    – muru
    Commented Jul 12, 2022 at 7:01
  • 1
    You could use the window manager (e.g. wmctrl) to close it as you would manually...
    – pLumo
    Commented Jul 12, 2022 at 7:28
  • @pLumo about wmctrl — I'm Wayland-only, sorry for forgetting to add the tag.
    – user598527
    Commented Jul 12, 2022 at 7:57
  • 1
    Have a look at ydotool then. It simulates input rather than interacting with the Xserver. Should be available in most standard repos.
    – FelixJN
    Commented Jul 12, 2022 at 8:11

1 Answer 1

0

Please try something like this (is you have a single firefox profile - this might not work if you have two instances of Firefox running with two different profiles):

kill `ps -ej | grep -v grep | grep firefox | head -1 | awk '{print $1}'`

This works here just fine and I don't see any messages in regard to "Your session has been restored".

The command "kills" (sends the TERM signal which is a normal way of terminating applications in Linux) only the parent Firefox process which is how it's meant to be closed.

6
  • Fixed. I've totally forgotten about head. Commented Jul 12, 2022 at 20:00
  • How can the script be sure that the first process listed is the parent? PIDs can easily wrap such that the parent's PID is > the child's.
    – Jim L.
    Commented Jul 12, 2022 at 20:04
  • -j takes care of that. Commented Jul 12, 2022 at 20:21
  • Thanks. -j isn't documented in my Ubuntu 22 man page, other than Jobs format, whatever that is.
    – Jim L.
    Commented Jul 12, 2022 at 20:34
  • 1
    I apologize for the late reply. The same "Sorry. We’re having trouble getting your pages back." session restore page appears on fresh Fedora 36 and Ubuntu 22.04 LTS installations. I updated the systems after installing.
    – user598527
    Commented Oct 1, 2022 at 11:49

You must log in to answer this question.

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