Run flatpak firefox with a throw away profile

Solved

Hello Everyone,

for testing purposes i like to use "throw away" firefox profiles. Before switching to flatpak, i used a script which would simply do:

firefox.bin --profile "$(mktemp -d)" --no-remote

Trying the same with the flatpak firefox bundle

flatpak run org.mozilla.firefox --profile "$(mktemp -d)" --no-remote

results in an error that firefox can not find/access its profile directory.

Sadly i did not see anything obvious in man flatpak-run to fix this, so i now
hope someone can help me out or point me in the right direction.

Posted Sep 21, 2021, 11:28 PM UTC

55

With that command

flatpak run org.mozilla.firefox --profile "$(mktemp -d)" --no-remote

the mktemp -d gets run by the shell on your host, so the temporary directory also gets created in /tmp on the host. To run it inside the sandbox, try something like this

flatpak run --command=sh org.mozilla.firefox -c 'firefox --profile "$(mktemp -d)" --no-remote'
3
igorlogiusOP:AMOB: Addon Developer•

I knew there was a better way of doing this. Thanks.

1
[deleted]•

[deleted]

1
igorlogiusOP:AMOB: Addon Developer•

I refined u/AlternativeOstrich7 suggestion a little and this seems to be a pretty contained and clean solution.

#!/bin/bash
flatpak run --command=bash org.mozilla.firefox -c '
set -x;
PDIR=$(mktemp -d -t firefox-temp-profile.XXXXXXXXXX); 
function cleanup { 
  rm -rf "$PDIR";
};
trap cleanup EXIT;
firefox --profile "$PDIR" --no-remote --new-instance;
';

--- edit update ---

  • removed mkdir
0

Looks interesting, but is that necessary? mktemp -d already creates the directory, so the mkdir seems superfluous. And the /tmp in the sandbox is a tmpfs that gets unmounted when the sandbox is closed. So the rm -rf also doesn't seem necessary. Or did I miss something?

1
igorlogiusOP:AMOB: Addon Developer•

Your right with the mkdir, that seems to be a remenant of some testing of mine.

Mmmh, about "/tmp" in the sandbox ... i am not sure, if it is a good idea to leave it as is.

1