Re: mozilla-xremote-client with profiles not working?

Corey Wright <[email protected]> Sun, 4 Sep 2005 01:34:05 -0500
Newsgroups gmane.comp.mozilla.devel.unix
Message-ID <[email protected]>
this email is in response to an earlier (11 jun 2005) email conversation
between brian utterback & paul wellner concerning running multiple firefox
profiles concurrently while targeting a specific profile with a remote command
("Re: mozilla-xremote-client with profiles not working?").

here's my situation (similar to brian's): i have one profile which is always
displaying a set of auto-refreshing system status web pages
(http://www.cacti.net) and another profile for general web surfing.  after
running for many days, viewing hundreds of random web pages during my daily
surfing, and consuming 1 gigabyte of ram, i can restart my general web surfing
profile, without affecting my system status profile, and firefox will be back
to a reasonable size.

my problem, like brian's, was that when using remote commands, firefox
complained about not finding a running instance because firefox is not setting
the _MOZILLA x properties (ie _MOZILLA_PROGRAM, _MOZILLA_PROFILE,
_MOZILLA_USER, _MOZILLA_VERSION).

granted the "proper" solution is patching firefox to set the desired x
properties on every new window, but my ignorance of the x-windows api and
mozilla codebase severely hampers me.

i'm using debian's firefox 1.0.4, which includes backported security patches
from 1.0.6.

after spending a late night researching x properties, learning to use xprop
and xwininfo, and testing the script for a week now, i have the following
solution:

- patch firefox shell script to use requested profiles
- write firefox-set-profile script to set x properties for firefox window
- write firefox wrapper script that calls firefox-set-profile when launching
new profile (though it's actually called "mozilla")

regardless of the acceptance of my other scripts, i consider it a bug that the
original firefox shell script does not allow a user to specify a profile,
which my patch addresses (though i admit i have not researched the issue
enough to know whether the script's fault lies in mozilla's sources, or
debian's packaging, so i might be speaking out of line).

process:
1. execute firefox wrapper script
  a. try to ping default profile
  b. launch default profile
  c. previous ping failed, execute "firefox-set-profile default"
2. execute "firefox-set-profile default"
  a. make user click on "Mozilla Firefox" entitled window
  b. set x properties for clicked window

3. user again executes firefox wrapper script
  a. try to ping default profile
  b. launch default profile
  c. previous ping successful, exit

4. user closes initial firefox window (and only firefox window with properly
set x properties) 5. user manually executes "firefox-set-profile default"
  a. make user click on "Mozilla Firefox" entitled window
  b. set x properties for clicked window
6. user executes firefox wrapper script
  a. try to ping default profile
  b. launch default profile
  c. previous ping successful, exit

bugs in my design & implementation:
1. firefox-set-profile sets x properties for clicked window, but x properties
do not apply for new windows spawned from same firefox process.  if you launch
a new firefox, set x properties for initial firefox window, open new firefox
window from initial window, and close initial window, then remote commands
will fail as the second and only remaining firefox window did not inherit the
x properties. 2. firefox-set-profile, by way of xwininfo, sometimes makes it
very hard to navigate to a firefox window on another virtual desktop, as
xwininfo hijacks the mouse.  only execute firefox-set-profile if the desired
firefox window is visible and easily reached by the mouse cursor.  if a new
firefox is launched by wrapper script, hope firefox window appears on current
virtual desktop.  the problem can be solved by limiting the number of xwininfo
executions within firefox-set-profile (ie "while [ -z ${ID} -a ${COUNTER} -lt
3 ]").

please specifically include me in any replies as i only subscribed to the list
to send this one email and i don't know how long i'll remain subscribed. -- 
[email protected]
firefox-profile_argument.patch (text/plain, 730 B)
--- /usr/lib/mozilla-firefox/firefox.orig	2005-05-16 21:07:46.000000000 -0500
+++ /usr/lib/mozilla-firefox/firefox	2005-08-27 07:06:20.000000000 -0500
@@ -235,6 +235,9 @@
             -a)
                 APPLICATION_ID="${arg}"
                 ;;
+            -P)
+                PROFILE="${arg}"
+                ;;
             --display)
                 CMDLINE_DISPLAY="${arg}"
                 set "$@" --display "${arg}"
@@ -325,6 +328,9 @@
 fi
 
 MOZ_PROGRAM="${MOZ_PROGRAM} -a ${APPLICATION_ID}"
+if [ "${PROFILE}" ]; then
+    MOZ_PROGRAM="${MOZ_PROGRAM} -P ${PROFILE}"
+fi
 
 echo_vars FIREFOX_DSP APPLICATION_ID CMDLINE_DISPLAY DISPLAY REMOTE \
           TRY_USE_EXIST OPTIONS DEBUG DEBUGGER
firefox-set-profile (text/plain, 517 B)
#!/bin/sh
if [ "${#}" != 1 ]; then
  echo usage: ${0} PROFILE
  exit 1
fi

ID=""

while [ -z ${ID} ]; do
  ID=$(xwininfo \
       | grep '^xwininfo: Window id: 0x.*Mozilla Firefox"' \
       | cut -f4 -d' ')
done

xprop -id ${ID} -f _MOZILLA_PROGRAM 8s -set _MOZILLA_PROGRAM firefox
xprop -id ${ID} -f _MOZILLA_PROFILE 8s -set _MOZILLA_PROFILE "${1}"
xprop -id ${ID} -f _MOZILLA_USER    8s -set _MOZILLA_USER    "$(whoami)"
xprop -id ${ID} -f _MOZILLA_VERSION 8s -set _MOZILLA_VERSION 5.0

exit 0
mozilla (text/plain, 137 B)
#!/bin/sh
firefox -P default -remote 'ping()'
PING=${?}
firefox -P default "${@}" &
[ ${PING} != 0 ] && firefox-set-profile default