I need to be able to get the URL from the active tab in Firefox. DDE doesn\'t work with multiple instances so I was thinking that I could build an addon that sets a global
The usual way of communicating from an application to a Firefox add-on is via TCP sockets. You create an nsIServerSocket instance, call init()
on it and then asyncListen()
. When the application connects to your socket the method onSocketAccepted of your listener gets called and you get an nsITransport instance that you can read data from or write to (use NetUtil.jsm to read from the input stream asynchronously).
For a relatively simply example implementation see mozSocket.jsm (not using NetUtils.jsm
for reading data).
I wonder if this has been implemented in Firefox yet or if it's still in the idea phase: Mozilla Notifications API.
Google has GCM for Chrome extensions.
I don't know if its the best way, but I think using MozRepl will help you. MozRepl will make you able to interact with firefox through telnet.
% telnet localhost 4242
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Welcome to MozRepl.
repl> content.location.href
"http://stackoverflow.com/questions/8525428/whats-the-best-way-to-communicate-with-a-firefox-addon"
repl>
After installing MozRepl, You can use this little ruby script to get the url of currently opend tab.
require 'net/telnet'
t = Net::Telnet.new('Port' => 4242)
t.waitfor(/repl.*>/)
puts eval(t.cmd("content.location.href").split[0])
t.close