summaryrefslogtreecommitdiff
path: root/doc/FirefoxDBusRemoteControl.html
blob: cbbbaaefe94bcd5cfbbcc5bdee254e08176fe2bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<html> <head>
	<title> Chris&#39;s Wiki :: blog/unix/FirefoxDBusRemoteControl </title>
	<link href="https://utcc.utoronto.ca/~cks/dwiki/dwiki.css" rel="stylesheet" type="text/css"> 
	<meta name="viewport" content="width=device-width">
	<link rel="alternate" type="application/atom+xml" href="https://utcc.utoronto.ca/~cks/space/blog/?atom">
	
</head>
<body>
<div id="header">
	<div class="left"><a href="https://utcc.utoronto.ca/~cks/">Chris Siebenmann</a> ::
<span class="breadcrumbs"><a href="https://utcc.utoronto.ca/~cks/space/">CSpace</a> &raquo;
       <a href="https://utcc.utoronto.ca/~cks/space/blog/">blog</a> &raquo;
       <a href="https://utcc.utoronto.ca/~cks/space/blog/unix/">unix</a> &raquo;
       FirefoxDBusRemoteControl</span></div>
	<div class="right">Welcome, guest.</div>
</div>

<div id="documentbody">
<div class="wtblog">
<div class="maintext"> 
	   <div class="wikitext titlehack"><h2>Firefox now implements its remote control partly over D-Bus</h2>

	<div class="posttitle" style="opacity: 0.6;"><small>August  3, 2018</small></div>
</div>
<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
remote control a running Firefox instance</a>.
This has traditionally worked through X properties (with <a href="https://utcc.utoronto.ca/~cks/space/blog/programming/GoLowLevelX">two
generations of protocols</a>), which has
the nice advantage that it works from remote machines as well as
your local one, provided that you're forwarding X. Since I read my
mail through <a href="http://beedub.com/exmh/">exmh</a> that's running on one
of our servers, not my desktop, this is pretty useful for me; I can
click on a link in mail in exmh, and it opens in my desktop Firefox.
However, working through X properties also has the disadvantage
that it naturally doesn't work at all on <a href="https://en.wikipedia.org/wiki/Wayland_(display_server_protocol)">Wayland</a>.  Since
Wayland is increasingly important, last November or so the Mozilla
people fixed this by adding a new D-Bus based protocol (it landed
in <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1360560">bug 1360560</a>
and <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=1360566">bug 1360566</a>
but has evolved in various ways since then).</p>

<p>On current versions of Firefox, you will find this service on the
session bus under the name org.mozilla.firefox.&lt;something>, where
the &lt;something> is often 'ZGVmYXVsdA__'. In general this weird
thing is the base64 encoded name of your Firefox profile with a few
special characters turned into _, and that particular name is,
well:</p>

<blockquote><pre style="white-space: pre-wrap;">
; echo -n default | base64
ZGVmYXVsdA==
</pre>
</blockquote>

<p>Because this directly encodes the profile name in something that
you have to get right, the D-Bus based version of Firefox remote
control will reliably restrict itself to talking to a running Firefox
that's using the same profile; the X properties based version doesn't
always (or didn't always, at any rate).  You can force a new Firefox
to not try to talk to an existing Firefox by using <code>--new-instance</code>,
as before.</p>

<p>(One case where you might need this is if you're testing an
alternate version of Firefox by manually setting your <code>$HOME</code>
to, eg, <code>/tmp/ffox-test</code>.)</p>

<p>It turns out that which protocol Firefox uses when is a bit tangled.
If Firefox is built with D-Bus support, a running Firefox on X will
be listening for incoming requests using both D-Bus and the X
properties based protocol; you can talk to this Firefox with either.
In the current Firefox code, if you built with both D-Bus and Wayland
support, the client Firefox always uses D-Bus to try to talk to the
running 'server' Firefox; it doesn't fall back to X properties if
there's no D-Bus available. If you built Firefox without Wayland
support, it always uses the X properties based protocol (even if
you built with D-Bus, and so the running Firefox is listening there).
You 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>

<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
Firefox tried to use the X properties based remote control if it
was running on X, and fell back to the D-Bus protocol otherwise.
In thinking about it I've come to believe that the logic here is
sound, because in a Wayland session you may have some programs that
think they're running in X and then pass this view on to things run
from them. D-Bus is more session type agnostic, although it only
works on the local machine.</p>

<p>Note that this implies that you can no longer use Firefox itself
as a client on a second machine, at least not if your second machine
Firefox is a modern one that was built with Wayland support; it'll
try to talk D-Bus and fail because your running Firefox isn't on
that machine. If you want to remote control Firefox from a second
machine, you now want a dedicated client like <a href="https://github.com/siebenmann/ffox-remote">my <code>ffox-remote</code>
program</a>.</p>

<p>(Hopefully Mozilla will leave the X properties based protocol there
for many years to come, so my cross-machine remote control will still
keep working.)</p>

<h3>Sidebar: some D-Bus protocol details</h3>

<p>The D-Bus object path is /org/mozilla/firefox/Remote, which has one
org.mozilla.firefox method, <code>OpenURL()</code>, all of which you can see
by using a D-Bus browsing program such as <a href="https://wiki.gnome.org/Apps/DFeet">d-feet</a>. In the Firefox source code,
what you want to look at is widget/xremoteclient/DBusRemoteClient.cpp
(the client side, ie the <code>firefox</code> command you just ran that is
going to pass your URL or whatever to the currently running one)
and toolkit/components/remote/nsDBusRemoteService.cpp (the server
side, ie the running Firefox).</p>

<p>Despite the fact that D-Feet will tell you that the argument to
<code>OpenURL()</code> is a string, in actuality it's an entire command line
encoded in the same annoying binary encoding that is used in the
current X property based protocol, which you can read a concise
description of in <a href="https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/remote/nsRemoteService.cpp#l165">nsRemoteService.cpp</a>.
Presumably this minimizes code changes, although it's not the most
natural D-Bus interface. This encoding does mean that you're going
to need some moderately tangled code to remote-control Firefox over
D-Bus; you can't fire up just any old D-Bus client program for it.</p>

<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>,
in the <code>StartRemoteClient()</code> function.</p>
</div>
<hr>
<h3> <a name="comments">Comments</a> on this page: </h3>
<div class="comments">
<div class="comment">
<div class="entryid"> By Tüdelbüdel at <a name="guest-20180804070451">2018-08-04 07:04:51</a>: </div>
<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>

<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>

<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>

<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>
</div> </blockquote> </div>

</div>
	<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>
<table border=0 width="100%"> 
<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>
     <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>
</table>
</div>
<div class="sidebar">
	<div class="readme"> <div class="wikitext"><p>These are my <a href="https://utcc.utoronto.ca/~cks/space/blog/">WanderingThoughts</a> <br>
(<a href="https://utcc.utoronto.ca/~cks/space/AboutBlog">About the blog</a>)</p>

<p><a href="https://utcc.utoronto.ca/~cks/space/blog/__Index">Full index of entries</a> <br>
<a href="https://utcc.utoronto.ca/~cks/space/blog/__RecentComments">Recent comments</a></p>

<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>
Mastodon: <a href="https://mastodon.social/@cks">@cks</a> <br>
<strike>Twitter</strike>: <a href="https://twitter.com/thatcks/">@thatcks</a></p>

<p align="center">* * *</p>

<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>
Also: <a href="https://utcc.utoronto.ca/~cks/space/blog/__Topics">(Sub)topics</a></p>

<p>This is a <a href="https://utcc.utoronto.ca/~cks/space/dwiki/DWiki">DWiki</a>. <br>
<a href="https://utcc.utoronto.ca/~cks/space/help/GettingAround">GettingAround</a> <br>
(<a href="https://utcc.utoronto.ca/~cks/space/help/Help">Help</a>)</p>
</div> </div>
<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>
</div>
</div>
 
</div>

<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>. 
<div class="bottombar">
	<div class="left"><form method=get action="https://utcc.utoronto.ca/~cks/space/">Search: <input name=search size=15></form></div>
	<div class="right"><form method=post action="https://utcc.utoronto.ca/~cks/space/.login">
Login: <input name=login size=10>
Password: <input type=password name=password size=10>
<input type=hidden name=view value=login>
<input type=hidden name=page value="blog/unix/FirefoxDBusRemoteControl">
<input type=submit value="Login"></form></div> <div class="clear"></div>
</div>
<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>

<hr> Last modified: Fri Aug  3 23:00:04 2018 <br>
<address>This dinky wiki is brought to you by the Insane Hackers
Guild, Python sub-branch.</address>
</body>
</html>