ほかのFirefox extensionからFirebugのコンソールにデバッグ出力を出す

Firebugのconsole.log()は、ほかのextensionの中からは console is not undefined といわれて呼び出すことができません。ブラウザでconsoleは開いているウインドウとFirebugのコンソールでしか有効でないシンボルのようです。

Firebugのコンソールであれば、中を見たいものが複雑な構造をしていてもクリックしていくことで中を見ていくことができるので、テキストでしか表示できないwindow.dumpと比べてすごく便利なのでつかえないのかなー、と思っていたらふつうに
Firebug.Console.log( obj )
で呼び出せば、ほかのextensionの中からでもFirebugのコンソールに出力することができました。

Execute JS を使って拡張機能のコンテキストで実行してもconsole.logしたときと同じかたちでFirebugのコンソールに結果が出てきます。
Firebugconsole

どういうしくみなのか

Frebugのコンソールが使えないのかなー、と思っていたときに、そういえば YSlowはFirebugにくっついてたなというのを思い出して、中を見てみたらどこかで宣言することもなくいきなりFirebugという定数を使っているので今度はFirebug側のコードを見てみたら chrome/content/firebug/firebug.js に
top.Firebug =
{
    version: "1.05",

    module: modules,
    panelTypes: panelTypes,
    reps: reps,
という部分があるのを見つけました。extensionの実行コンテキストでのtopが何なのか、さっそく Firebug.Console.log(top) で見てみると ChromeWindow オブジェクトで chrome://browser/content/browser.xul を指していました。 Console.logのほかはそんなに有用ではないかもしれませんが、ついでに grep -hrPw '^top\.' * してみると
top.FirebugChrome =
top.domplate = function()
top.TAG = function()
top.FOR = function()
top.Firebug =
top.InsideOutBox = function(view, box)
top.SourceCache = function(context)
top.SourceCache.prototype =
top.XMLHttpRequestSpy = function(request, context, win)
top.TabWatcher =
なんていうのがFirebug内でtopに代入されていました。

tags

  • Firefox
  • debug
  • extension
  • 「ほかのFirefox extensionからFirebugのコンソールにデバッグ出力を出す」のはてなブックマーク数
  • 「ほかのFirefox extensionからFirebugのコンソールにデバッグ出力を出す」deliciousブックマーク数
  • 「ほかのFirefox extensionからFirebugのコンソールにデバッグ出力を出す」をはてなブックマークに追加
  • save "ほかのFirefox extensionからFirebugのコンソールにデバッグ出力を出す" to del.icio.us
  • 「ほかのFirefox extensionからFirebugのコンソールにデバッグ出力を出す」をリアルタイムブログ検索
  • permalink
  • javascriptを拡張機能のコンテキストで実行できる Execute JS
  • Firefoxのsqliteデータベースの中身を表示する Storage Inspector

comments

TypeKey Enabled
スタイル用のHTMLタグが使えます。
*required

trackbacks

トラックバック元エントリにこのエントリへのリンクがない場合はトラックバックを受け付けません。

http://labs.gmo.jp/mt/mt-tb.cgi/149
©2010 Kentaro Kumagai, GMO Internet Labs., GMO Internet, inc.
bits and bytes
2007 .07. 31 18:04

tagcloud

  • API1
  • C/C++2
  • E4X1
  • FUSE2
  • Firefox18
  • HTML4
  • IE1
  • MySQL1
  • OSX4
  • Opera2
  • PHP4
  • XML1
  • XPCOM4
  • XPath3
  • apache2
  • binary2
  • book1
  • data11
  • debug4
  • design1
  • experiments3
  • extension10
  • google gears1
  • google maps API1
  • greasemonkey3
  • httpd5
  • javascript17
  • linux1
  • logging2
  • mobile3
  • perl4
  • tips4
  • tool11
  • vim2
  • visualization2
  • widget1
  • wii1
  • windows7
  • サービス6
  • 和訳1

Archives

  • 2008.02 (6)
  • 2008.01 (3)
  • 2007.12 (4)
  • 2007.11 (5)
  • 2007.10 (4)
  • 2007.09 (4)
  • 2007.08 (4)
  • 2007.07 (8)
  • 2007.06 (7)
  • 2007.05 (4)
  • 2007.04 (5)
  • 2007.03 (6)
  • 2007.02 (4)
  • 2007.01 (6)

about

  • bits and bytesのXML
  • 「bits and bytes」のCreative Commons
  • Powered by Movable Type
  • イベントと地図 - モグ
  • Use ecto to blog!
  • bits and bytesのはてなブックマーク数
  • bits and bytesをMy Yahoo!に追加
  • Subscribe with Bloglines