Are you Facebook developer and frustrated by your inability to use a JavaScript console to debug your application on Facebook? Good news, with the release of Firefox 4 and the latest version of Firebug (1.7.0)- now you can!

To access an iframe Facebook application’s context enter cd(frames[0]); into your Firebug console. This will work on both Canvas and Tab applications.

UPDATE – 2011/06/13: It appears that Facebook has modified their code. You now have to enter cd(frames[0]);, instead of cd(frames[1]);, to access the appropriate frame within Firebug.

By default, command line expressions are relative to the top-level window of the page. The Commandline API for Firebug’s JavaScript console exposes a ‘cd(window)’ method to alter the context of the console to a different window; however, prior to the release of Firefox 4 and Firebug 1.7.0 this functionality was throwing an error citing cross-domain issues. An excellent reason to upgrade if I do say so myself!

Debugging within a Facebook application's context

Note: The Webkit JavaScript console (latest Chrome and Safari builds as of the time of this post) currently does not allow switching the context of to a frame loaded from a different domain.

Tagged with: