1

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 atom or something.

I also thought that maybe I could use the clipboard, but I don't want to overwrite any existing text and custom clipboard types doesn't seem to be supported.

I don't want to resort to writing a file just to do simple IPC...so before I do it...is there a better choice for something so simple.

thanks

Iunknown
  • 347
  • 1
  • 2
  • 16
  • You could do something really silly like write out the current URL to a file every time it changes and read that file from the other process. – Wayne Dec 15 '11 at 19:35
  • You can find solution on this page: http://stackoverflow.com/questions/11582607/find-url-of-current-tab-making-a-firefox-browser-add-on – Tomasz Dzięcielewski Oct 10 '12 at 12:53

3 Answers3

2

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

Wladimir Palant
  • 56,865
  • 12
  • 98
  • 126
  • Using TCP sockets just to get the URL for the currently active tab sounds like overkill. Since I'm not a Java or Firefox guy, it looks like I'm going to have to go 'hack' and just write the URL to a file or something else as ugly. – Iunknown Dec 17 '11 at 03:11
2

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
rio
  • 65
  • 1
  • 5
1

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.

Monstieur
  • 7,992
  • 10
  • 51
  • 77