summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDebian Live user <user@debian-BULLSEYE-live-builder-AMD64>2023-04-29 07:15:16 -0400
committerDebian Live user <user@debian-BULLSEYE-live-builder-AMD64>2023-04-29 07:15:16 -0400
commitc08c6366ac75af046a689d908d262cfaa74477e9 (patch)
tree83097aa184ff4eb278fe16d0a966dc3534ea34e5
parent8398a3f0b397ed40bb405feadd592a871832767e (diff)
document the source code a little
-rw-r--r--doc/FirefoxDBusRemoteControl.html189
-rwxr-xr-xsrc/firestart3
2 files changed, 191 insertions, 1 deletions
diff --git a/doc/FirefoxDBusRemoteControl.html b/doc/FirefoxDBusRemoteControl.html
new file mode 100644
index 0000000..cbbbaae
--- /dev/null
+++ b/doc/FirefoxDBusRemoteControl.html
@@ -0,0 +1,189 @@
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
2 "http://www.w3.org/TR/html4/loose.dtd">
3<html> <head>
4 <title> Chris&#39;s Wiki :: blog/unix/FirefoxDBusRemoteControl </title>
5 <link href="https://utcc.utoronto.ca/~cks/dwiki/dwiki.css" rel="stylesheet" type="text/css">
6 <meta name="viewport" content="width=device-width">
7 <link rel="alternate" type="application/atom+xml" href="https://utcc.utoronto.ca/~cks/space/blog/?atom">
8
9</head>
10<body>
11<div id="header">
12 <div class="left"><a href="https://utcc.utoronto.ca/~cks/">Chris Siebenmann</a> ::
13<span class="breadcrumbs"><a href="https://utcc.utoronto.ca/~cks/space/">CSpace</a> &raquo;
14 <a href="https://utcc.utoronto.ca/~cks/space/blog/">blog</a> &raquo;
15 <a href="https://utcc.utoronto.ca/~cks/space/blog/unix/">unix</a> &raquo;
16 FirefoxDBusRemoteControl</span></div>
17 <div class="right">Welcome, guest.</div>
18</div>
19
20<div id="documentbody">
21<div class="wtblog">
22<div class="maintext">
23 <div class="wikitext titlehack"><h2>Firefox now implements its remote control partly over D-Bus</h2>
24
25 <div class="posttitle" style="opacity: 0.6;"><small>August 3, 2018</small></div>
26</div>
27<div class="wikitext"><p>On Unix, Firefox has had a long standing feature where <a href="https://utcc.utoronto.ca/~cks/space/blog/unix/WeirdFirefoxRemoteControl">you could
28remote control a running Firefox instance</a>.
29This has traditionally worked through X properties (with <a href="https://utcc.utoronto.ca/~cks/space/blog/programming/GoLowLevelX">two
30generations of protocols</a>), which has
31the nice advantage that it works from remote machines as well as
32your local one, provided that you're forwarding X. Since I read my
33mail through <a href="http://beedub.com/exmh/">exmh</a> that's running on one
34of our servers, not my desktop, this is pretty useful for me; I can
35click on a link in mail in exmh, and it opens in my desktop Firefox.
36However, working through X properties also has the disadvantage
37that it naturally doesn't work at all on <a href="https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)">Wayland</a>. Since
38Wayland is increasingly important, last November or so the Mozilla
39people fixed this by adding a new D-Bus based protocol (it landed
40in <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1360560">bug 1360560</a>
41and <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1360566">bug 1360566</a>
42but has evolved in various ways since then).</p>
43
44<p>On current versions of Firefox, you will find this service on the
45session bus under the name org.mozilla.firefox.&lt;something>, where
46the &lt;something> is often 'ZGVmYXVsdA__'. In general this weird
47thing is the base64 encoded name of your Firefox profile with a few
48special characters turned into _, and that particular name is,
49well:</p>
50
51<blockquote><pre style="white-space: pre-wrap;">
52; echo -n default | base64
53ZGVmYXVsdA==
54</pre>
55</blockquote>
56
57<p>Because this directly encodes the profile name in something that
58you have to get right, the D-Bus based version of Firefox remote
59control will reliably restrict itself to talking to a running Firefox
60that's using the same profile; the X properties based version doesn't
61always (or didn't always, at any rate). You can force a new Firefox
62to not try to talk to an existing Firefox by using <code>--new-instance</code>,
63as before.</p>
64
65<p>(One case where you might need this is if you're testing an
66alternate version of Firefox by manually setting your <code>$HOME</code>
67to, eg, <code>/tmp/ffox-test</code>.)</p>
68
69<p>It turns out that which protocol Firefox uses when is a bit tangled.
70If Firefox is built with D-Bus support, a running Firefox on X will
71be listening for incoming requests using both D-Bus and the X
72properties based protocol; you can talk to this Firefox with either.
73In the current Firefox code, if you built with both D-Bus and Wayland
74support, the client Firefox always uses D-Bus to try to talk to the
75running 'server' Firefox; it doesn't fall back to X properties if
76there's no D-Bus available. If you built Firefox without Wayland
77support, it always uses the X properties based protocol (even if
78you built with D-Bus, and so the running Firefox is listening there).
79You can see this sausage being made in <code>StartRemoteClient()</code> <a href="https://hg.mozilla.org/mozilla-central/file/tip/toolkit/xre/nsAppRunner.cpp#l1725">here</a>.</p>
80
81<p>This logic was introduced in the change for <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1465371">bug 1465371</a>. Before then
82Firefox tried to use the X properties based remote control if it
83was running on X, and fell back to the D-Bus protocol otherwise.
84In thinking about it I've come to believe that the logic here is
85sound, because in a Wayland session you may have some programs that
86think they're running in X and then pass this view on to things run
87from them. D-Bus is more session type agnostic, although it only
88works on the local machine.</p>
89
90<p>Note that this implies that you can no longer use Firefox itself
91as a client on a second machine, at least not if your second machine
92Firefox is a modern one that was built with Wayland support; it'll
93try to talk D-Bus and fail because your running Firefox isn't on
94that machine. If you want to remote control Firefox from a second
95machine, you now want a dedicated client like <a href="https://github.com/siebenmann/ffox-remote">my <code>ffox-remote</code>
96program</a>.</p>
97
98<p>(Hopefully Mozilla will leave the X properties based protocol there
99for many years to come, so my cross-machine remote control will still
100keep working.)</p>
101
102<h3>Sidebar: some D-Bus protocol details</h3>
103
104<p>The D-Bus object path is /org/mozilla/firefox/Remote, which has one
105org.mozilla.firefox method, <code>OpenURL()</code>, all of which you can see
106by using a D-Bus browsing program such as <a href="https://wiki.gnome.org/Apps/DFeet">d-feet</a>. In the Firefox source code,
107what you want to look at is widget/xremoteclient/DBusRemoteClient.cpp
108(the client side, ie the <code>firefox</code> command you just ran that is
109going to pass your URL or whatever to the currently running one)
110and toolkit/components/remote/nsDBusRemoteService.cpp (the server
111side, ie the running Firefox).</p>
112
113<p>Despite the fact that D-Feet will tell you that the argument to
114<code>OpenURL()</code> is a string, in actuality it's an entire command line
115encoded in the same annoying binary encoding that is used in the
116current X property based protocol, which you can read a concise
117description of in <a href="https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/remote/nsRemoteService.cpp#l165">nsRemoteService.cpp</a>.
118Presumably this minimizes code changes, although it's not the most
119natural D-Bus interface. This encoding does mean that you're going
120to need some moderately tangled code to remote-control Firefox over
121D-Bus; you can't fire up just any old D-Bus client program for it.</p>
122
123<p>The client code for this is in <a href="https://hg.mozilla.org/mozilla-central/file/tip/toolkit/xre/nsAppRunner.cpp">toolkit/xre/nsAppRunner.cpp</a>,
124in the <code>StartRemoteClient()</code> function.</p>
125</div>
126<hr>
127<h3> <a name="comments">Comments</a> on this page: </h3>
128<div class="comments">
129<div class="comment">
130<div class="entryid"> By Tüdelbüdel at <a name="guest-20180804070451">2018-08-04 07:04:51</a>: </div>
131<blockquote> <div class="wikitext"><p>Ah yes, the remote control feature, because it is SO FUNNY if you want to open /home/tuedel/localinfo.html and the request gets sent to a totally different computer. </p>
132
133<p>That was literally the only time I was confronted with that feature. It took a while to figure out what was even happening and then how to avoid it. Even with my current knowledge, I would be hard pressed to find the relevant section in the firefox user documentation.</p>
134
135<p>And this seems to be a general problem with complex software (browsers, *office, gimp etc.): You can start using them without reading any documentation, but when strange complex things happen or when you need more in-depth information on some feature, the answer will more likely be found in a stackoverflow posting or something, not the built in documentation.</p>
136
137<p>Of course it would be a huge effort to always write and maintain such comprehensive and in-depth documentation, so I am not complaining.</p>
138</div> </blockquote> </div>
139
140</div>
141 <small>Written on <a href="https://utcc.utoronto.ca/~cks/space/blog/2018/08/03/">03</a> <a href="https://utcc.utoronto.ca/~cks/space/blog/2018/08/">August</a> <a href="https://utcc.utoronto.ca/~cks/space/blog/2018/">2018</a>.</small> <br>
142<table border=0 width="100%">
143<tr> <td width="50%" style="padding-right: 0.5em"> <table> <tr> <td> &laquo; </td> <td> <a href="https://utcc.utoronto.ca/~cks/space/blog/programming/GoVersionedModulesDesire">How I want to use Go's versioned modules</a> </td> </tr> </table> </td>
144 <td width="50%" style="padding-left: 0.5em; border-left: 1px dotted;"> <table> <tr> <td> <a href="https://utcc.utoronto.ca/~cks/space/blog/tech/EmailVsModernProtocols">Why email is often not as good as modern communication protocols</a> </td> <td> &raquo; </td> </tr> </table> </td> </tr>
145</table>
146</div>
147<div class="sidebar">
148 <div class="readme"> <div class="wikitext"><p>These are my <a href="https://utcc.utoronto.ca/~cks/space/blog/">WanderingThoughts</a> <br>
149(<a href="https://utcc.utoronto.ca/~cks/space/AboutBlog">About the blog</a>)</p>
150
151<p><a href="https://utcc.utoronto.ca/~cks/space/blog/__Index">Full index of entries</a> <br>
152<a href="https://utcc.utoronto.ca/~cks/space/blog/__RecentComments">Recent comments</a></p>
153
154<p>This is part of <a href="https://utcc.utoronto.ca/~cks/space/FrontPage">CSpace</a>, and is written by <a href="https://utcc.utoronto.ca/~cks/space/People/ChrisSiebenmann">ChrisSiebenmann</a>. <br>
155Mastodon: <a href="https://mastodon.social/@cks">@cks</a> <br>
156<strike>Twitter</strike>: <a href="https://twitter.com/thatcks/">@thatcks</a></p>
157
158<p align="center">* * *</p>
159
160<p>Categories: <a href="https://utcc.utoronto.ca/~cks/space/blog/links/">links</a>, <a href="https://utcc.utoronto.ca/~cks/space/blog/linux/">linux</a>, <a href="https://utcc.utoronto.ca/~cks/space/blog/programming/">programming</a>, <a href="https://utcc.utoronto.ca/~cks/space/blog/python/">python</a>, <a href="https://utcc.utoronto.ca/~cks/space/blog/snark/">snark</a>, <a href="https://utcc.utoronto.ca/~cks/space/blog/solaris/">solaris</a>, <a href="https://utcc.utoronto.ca/~cks/space/blog/spam/">spam</a>, <a href="https://utcc.utoronto.ca/~cks/space/blog/sysadmin/">sysadmin</a>, <a href="https://utcc.utoronto.ca/~cks/space/blog/tech/">tech</a>, <a href="https://utcc.utoronto.ca/~cks/space/blog/unix/">unix</a>, <a href="https://utcc.utoronto.ca/~cks/space/blog/web/">web</a> <br>
161Also: <a href="https://utcc.utoronto.ca/~cks/space/blog/__Topics">(Sub)topics</a></p>
162
163<p>This is a <a href="https://utcc.utoronto.ca/~cks/space/dwiki/DWiki">DWiki</a>. <br>
164<a href="https://utcc.utoronto.ca/~cks/space/help/GettingAround">GettingAround</a> <br>
165(<a href="https://utcc.utoronto.ca/~cks/space/help/Help">Help</a>)</p>
166</div> </div>
167<div class="sidesearch" style="font-size: small"> <form method=get action="https://utcc.utoronto.ca/~cks/space/">Search: <input name=search size=15></form> </div>
168</div>
169</div>
170
171</div>
172
173<hr> Page tools: <a href="https://utcc.utoronto.ca/~cks/space/blog/unix/FirefoxDBusRemoteControl?source" rel="nofollow">View Source</a>, <a href="https://utcc.utoronto.ca/~cks/space/blog/unix/FirefoxDBusRemoteControl">View Normal</a>, <a href="https://utcc.utoronto.ca/~cks/space/blog/unix/FirefoxDBusRemoteControl?writecomment" rel="nofollow">Add Comment</a>.
174<div class="bottombar">
175 <div class="left"><form method=get action="https://utcc.utoronto.ca/~cks/space/">Search: <input name=search size=15></form></div>
176 <div class="right"><form method=post action="https://utcc.utoronto.ca/~cks/space/.login">
177Login: <input name=login size=10>
178Password: <input type=password name=password size=10>
179<input type=hidden name=view value=login>
180<input type=hidden name=page value="blog/unix/FirefoxDBusRemoteControl">
181<input type=submit value="Login"></form></div> <div class="clear"></div>
182</div>
183<div id="atomfeeds">Atom Syndication: <a type="application/atom+xml" href="https://utcc.utoronto.ca/~cks/space/blog/unix/FirefoxDBusRemoteControl?atomcomments" rel="nofollow">Recent Comments</a>.</div>
184
185<hr> Last modified: Fri Aug 3 23:00:04 2018 <br>
186<address>This dinky wiki is brought to you by the Insane Hackers
187Guild, Python sub-branch.</address>
188</body>
189</html>
diff --git a/src/firestart b/src/firestart
index 5cc1c92..5df8b50 100755
--- a/src/firestart
+++ b/src/firestart
@@ -25,10 +25,11 @@ then
25 # 25 #
26 # A more "correct" approach is available here: 26 # A more "correct" approach is available here:
27 # https://github.com/ayosec/findfox 27 # https://github.com/ayosec/findfox
28 # See also the file doc/FirefoxDBusRemoteControl.html in this repo.
28 exec systemd-run \ 29 exec systemd-run \
29 --user \ 30 --user \
30 --property Environment="DISPLAY=$DISPLAY" \ 31 --property Environment="DISPLAY=$DISPLAY" \
31 --property Environment=XAUTHORITY="$XAUTHORITY" \ 32 --property Environment="XAUTHORITY=$XAUTHORITY" \
32 --property TasksMax=2 \ 33 --property TasksMax=2 \
33 --wait \ 34 --wait \
34 --pipe \ 35 --pipe \