私はそれが最善の方法であるかどうかわかりませんが、私はMozReplを使用すると助けになると思います。 MozReplはtelnetを通じてfirefoxとやりとりすることができます。
% 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>
MozReplをインストールした後、この小さなルビースクリプトを使用して、現在開いているタブのURLを取得できます。
require 'net/telnet'
t = Net::Telnet.new('Port' => 4242)
t.waitfor(/repl.*>/)
puts eval(t.cmd("content.location.href").split[0])
t.close
出典
2012-01-20 20:27:38
rio
変更するたびに現在のURLをファイルに書き出し、そのファイルを他のプロセスから読み込むような何かをするのは本当にばかげているかもしれません。 –
このページで解決策を見つけることができます:http://stackoverflow.com/questions/11582607/find-url-of-current-tab-making-a-firefox-browser-add-on –