Bug 260239 - www/firefox: Can't open URL in running instance
Summary: www/firefox: Can't open URL in running instance
Status: New
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Many People
Assignee: freebsd-gecko (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-12-05 12:12 UTC by Michael Eriksson
Modified: 2021-12-11 18:02 UTC (History)
2 users (show)

See Also:
bugzilla: maintainer-feedback? (gecko)


Attachments
Log printout from firefox-esr (good) and firefox (broken) (11.96 KB, patch)
2021-12-05 12:12 UTC, Michael Eriksson
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Eriksson 2021-12-05 12:12:07 UTC
Created attachment 229923 [details]
Log printout from firefox-esr (good) and firefox (broken)

Executing "firefox <URL>" to open a URL in a running instance does not work with the recent versions of the firefox port, the latest I have tried with is firefox-95.0,2. It still works with firefox-esr.

Symptoms when running "firefox freebsd.org" when another Firefox instance is running:

1. A popup window is shown with the text "Firefox is already running, but is not responding. To use Firefox, you must first close the existing Firefox process, restart your device, or use a different profile."

2. Firefox writes this five times to standard error:
JavaScript error: resource://gre/modules/XULStore.jsm, line 66: Error: Can't find profile directory.

I have tested in a completely empty home directory (by setting $HOME). The logs from the running instances are attached. The file includes two logs:

- firefox-esr-91.4.0,1, where opening the URL worked
- firefox-95.0,2, where opening the URL failed
Comment 1 Christoph Moench-Tegeder freebsd_committer 2021-12-06 20:41:15 UTC
Can't reproduce, works as expected.
My first guess would be some dbus problem - you could use dbus-monitor to watch for the messages there.
Comment 2 Michael Eriksson 2021-12-07 08:17:41 UTC
You are right that this was a dbus problem. However,

1. firefox-esr, and most likely also earlier versions of mainline firefox, don't use dbus for opening URLs in running instances. This can be verified by testing without dbus running or by watching dbus-monitor.

2. The firefox port doesn't make sure that the machine is ready for running dbus (mainly by running "dbus-uuidgen --ensure"), and does not mention dbus in the pkg-message.

3. firefox can be built without the DBUS option, how will this work then?
Comment 3 Jan Beich freebsd_committer 2021-12-07 11:03:27 UTC
(In reply to Michael Eriksson from comment #2)
> 1. firefox-esr, and most likely also earlier versions of mainline firefox,
> don't use dbus for opening URLs in running instances. This can be verified by
> testing without dbus running or by watching dbus-monitor.

Before https://hg.mozilla.org/mozilla-central/rev/ef22d8cbf4ef one had to define MOZ_DBUS_REMOTE via environ(7) to use DBus on X11 to open a window in an existing Firefox instance.

> 2. The firefox port doesn't make sure that the machine is ready for running
> dbus (mainly by running "dbus-uuidgen --ensure"), and does not mention dbus in
> the pkg-message.

machine-id is mainly used by autolaunch and generic to all DBus consumers. If you start session bus (as user after login) manually then neither "dbus-uuidgen --ensure" nor "service dbus onestart" are required e.g.,

  $ cat >>/etc/profile
  # WARNING: zsh doesn't read this file by default, so use /etc/zprofile instead
  # XDG_RUNTIME_DIR is preferred but usually requires pam_xdg or consolekit2 (pam_ck_connector or ck_launch_session)
  if [ -n "$XDG_RUNTIME_DIR" ]; then
      if ! pgrep -qf -U ${USER:-$(id -u)} dbus.\*--session; then
	  dbus-daemon --session --fork --address=unix:runtime=yes 2>/dev/null
	  # Only necessary for some apps that fail to find default session bus (e.g., Emacs, Chrome)
	  # https://gitlab.freedesktop.org/dbus/dbus/-/commit/e3f117e7610b
	  export DBUS_SESSION_BUS_ADDRESS=unix:path=$XDG_RUNTIME_DIR/bus
      fi
  else
      eval $(dbus-launch --sh-syntax --exit-with-session 2>/dev/null)
  fi

> 3. firefox can be built without the DBUS option, how will this work then?

On X11 by snooping X atoms to find matching window then setting _MOZILLA_COMMANDLINE on that window.

https://searchfox.org/mozilla-release/rev/dbc7c5ca1e5a/toolkit/components/remote/nsXRemoteClient.cpp#31-37

$ xwininfo -root -children | awk '/^[[:space:]]*0x/ { print $1 }' | xargs -n1 xprop -id | fgrep _MOZILLA
_MOZILLA_PROFILE(STRING) = "default-esr"
_MOZILLA_PROGRAM(STRING) = "firefox"
_MOZILLA_USER(STRING) = "you"
_MOZILLA_VERSION(STRING) = "5.1"

$ pkg install go git
$ git clone https://github.com/siebenmann/ffox-remote
$ cd ffox-remote
$ go build
$ ./ffox-remote -P default-esr https://lists.freebsd.org/
$ ./ffox-remote -P default-esr http://itisatrap.org/firefox/its-a-trap.html
Comment 4 Michael Eriksson 2021-12-07 21:11:51 UTC
(In reply to Jan Beich from comment #3)

(Thanks for the link to the Firefox commit, it's now clear why dbus is needed.)

The point with "making the machine ready for dbus" was that Firefox would then autolaunch dbus for the user. Having to update global or personal shell rc files to run Firefox seems suboptimal.

OK, Firefox without DBUS continues to use the old method for communication between instances, fine.