Command Line API

From FirebugWiki

(Difference between revisions)
Jump to: navigation, search
m (Added category)
(21 intermediate revisions not shown)
Line 1: Line 1:
-
<p>The Firebug command line provides these special functions for your convenience:</p>
+
The Firebug [[Command Line]] provides these special functions for your convenience. These include functions to control the Firebug UI, functions interacting with the page, shortcuts for selectors and shortcuts for the [[Console API]]. Other browsers implement the Command Line API as well; the Chrome DevTools, Safari Inspector and Opera Dragonfly, implement most of what is below.
-
           
+
-
<h3>$(id)</h3>
+
-
<p>Returns a single element with the given id.</p>
+
=== [[help]] ===
 +
Returns a list of Command Line API commands including short descriptions.
-
<h3>$$(selector)</h3>
+
=== [[$|$(selector)]] ===
-
<p>Returns an array of elements that match the given CSS selector.</p>
+
Returns a single element matching the given CSS selector.
-
<h3>$x(xpath)</h3>
+
In old Firebug versions, this used to be equivalent to document.getElementById.
-
<p>Returns an array of elements that match the given XPath expression.</p>
+
-
<h3>$0</h3>
+
=== [[$$|$$(selector)]] ===
-
<p>The currently-selected object in the inspector.</p>
+
Returns an array of elements that match the given CSS selector.
-
<h3>$1</h3>
+
=== [[$x|$x(xpath)]] ===
-
<p>The previously-selected object in the inspector.</p>
+
Returns an array of elements that match the given XPath expression.
-
<h3>$n(index)</h3>
+
=== [[$0]] ===
-
<p>Access to an array of last 5 inspected elements.</p>
+
Represents the last element selected via the [[Inspector]].
-
<h3>dir(object)</h3>
+
=== [[$1]] ===
-
<p>Prints an interactive listing of all properties of the object.  This looks identical to the view that you would see in the DOM tab.</p>
+
Represents the second last element selected via the [[Inspector]].
-
<h3>dirxml(node)</h3>
+
=== [[dollar-underscore|$_]] ===
-
<p>Prints the XML source tree of an HTML or XML element.  This looks identical to the view that you would see in the HTML tab.  You can click on any node to inspect it in the HTML tab.</p>
+
Returns the value of the most recently evaluated expression in the [[Command Line]].
-
<h3>cd(window)</h3>
+
=== [[$p]] ===
 +
A container of arbitrary JavaScript values, after right-clicking them and selecting "Use in Command Line".
-
<p>By default, command line expressions are relative to the top-level window of the page.  cd() allows you to use the window of a frame in the page instead.</p>
+
=== [[$n|$n(index)]] ===
 +
Returns one of the 5 last elements selected via the [[Inspector]]. This method takes one required parameter <code>index</code>, which represents the index of the element (starting at 0).
-
<h3>clear()</h3>
+
=== [[dir|dir(object)]] ===
-
<p>Clears the console.</p>
+
Prints an interactive listing of all properties of the object. This looks identical to the view that inside the [[DOM Panel]].
-
<h3>inspect(object[, tabName])</h3>
+
=== [[dirxml|dirxml(node)]] ===
-
<p>Inspects an object in the most suitable tab, or the tab identified by the optional argument <code>tabName</code>.</p>
+
Prints the XML source tree of an HTML or XML element. This looks identical to the view inside the [[HTML Panel]]. You can click on any node to inspect it in the HTML panel.
-
<p>The available tab names are "html", "css", "script", and "dom".</p>
+
=== [[cd|cd(window)]] ===
 +
By default, command line expressions are relative to the top-level window of the page.  cd() allows you to use the window of a frame in the page instead.
-
<h3>keys(object)</h3>
+
=== [[clear|clear()]] ===
-
<p>Returns an array containing the names of all properties of the object.</p>
+
Clears the console.
-
<h3>values(object)</h3>
+
=== [[copy|copy(object)]] ===
-
<p>Returns an array containing the values of all properties of the object.</p>
+
Copies the given parameter to the clipboard. This can be a return value of a function or an object.
-
<h3>debug(fn)</h3>
+
=== [[inspect|inspect(object[, panelName])]] ===
-
<p>Adds a breakpoint on the first line of a function.</p>
+
Inspects an object in the most suitable panel, or the panel identified by the optional argument <code>panelName</code>.
-
<h3>undebug(fn)</h3>
+
The available tab names are "html", "stylesheet", "script", and "dom".
-
<p>Removes the breakpoint on the first line of a function.</p>
+
-
<h3>monitor(fn)</h3>
+
=== [[keys|keys(object)]] ===
 +
Returns an array containing the names of all properties of the object.
-
<p>Turns on logging for all calls to a function.</p>
+
=== [[values|values(object)]] ===
 +
Returns an array containing the values of all properties of the object.
-
<h3>unmonitor(fn)</h3>
+
=== [[include|include(url[, alias]) / include(alias)]] ===
-
<p>Turns off logging for all calls to a function.</p>
+
Includes a remote script.
-
<h3>monitorEvents(object[, types])</h3>
+
=== [[debug|debug(fn)]] ===
-
<p>Turns on logging for all events dispatched to an object. The optional argument <code>types</code> may specify a specific family of events to log.  The most commonly used values for <code>types</code> are "mouse" and "key".</p>
+
Adds a breakpoint on the first line of a function.
-
<p>The full list of available types includes "composition", "contextmenu", "drag", "focus", "form", "key", "load", "mouse", "mutation", "paint", "scroll", "text", "ui", and "xul".</p>
+
=== [[undebug|undebug(fn)]] ===
 +
Removes the breakpoint on the first line of a function.
-
<h3>unmonitorEvents(object[, types])</h3>
+
=== [[monitor|monitor(fn)]] ===
-
<p>Turns off logging for all events dispatched to an object.</p>
+
Turns on logging for all calls to a function.
-
<h3>profile([title])</h3>
+
=== [[unmonitor|unmonitor(fn)]] ===
-
<p>Turns on the JavaScript profiler.  The optional argument <code>title</code> would contain the text to be printed in the header of the profile report.</p>
+
Turns off logging for all calls to a function.
-
<h3>profileEnd()</h3>
+
=== [[monitorEvents|monitorEvents(object[, types])]] ===
-
<p>Turns off the JavaScript profiler and prints its report.</p>
+
Turns on logging for all events dispatched to an object. The optional argument <code>types</code> may define specific events or event types to log.
 +
 
 +
=== [[unmonitorEvents|unmonitorEvents(object[, types])]] ===
 +
Turns off logging for all events dispatched to an object. The optional argument <code>types</code> may define specific events or event families, for which to turn logging off.
 +
 
 +
For a list of available event families see [[monitorEvents|monitorEvents(object[, types])]].
 +
 
 +
=== [[profile|profile([title])]] ===
 +
Turns on the JavaScript profiler. The optional argument <code>title</code> contains the text to be printed in the header of the profile report.
 +
 
 +
=== [[profileEnd|profileEnd()]] ===
 +
Turns off the JavaScript profiler and prints its report.
 +
 
 +
=== [[table|table(data[, columns])]] ===
 +
This is a shortcut for <code>[[Console API#console.table.28data.5B.2C_columns.5D.29|console.table()]]</code>.
 +
 
 +
=== [[traceCalls|traceCalls(fn)]] ===
 +
Enables tracing of specific function calls.
 +
 
 +
=== [[untraceCalls|untraceCalls(fn)]] ===
 +
Disables tracing of specific function calls.
 +
 
 +
=== [[traceAll|traceAll()]] ===
 +
Enables tracing of function calls for a whole context.
 +
 
 +
=== [[untraceAll|untraceAll()]] ===
 +
Disables tracing of function calls for a whole context.
 +
 
 +
=== [[getEventListeners|getEventListeners()]] ===
 +
Returns all the event listeners registered for specific node (event target).
 +
 
 +
[[Category:Firebug]]
 +
[[Category:UI]]
 +
[[Category:API]]

Revision as of 23:57, 21 November 2013

The Firebug Command Line provides these special functions for your convenience. These include functions to control the Firebug UI, functions interacting with the page, shortcuts for selectors and shortcuts for the Console API. Other browsers implement the Command Line API as well; the Chrome DevTools, Safari Inspector and Opera Dragonfly, implement most of what is below.

Contents

help

Returns a list of Command Line API commands including short descriptions.

$(selector)

Returns a single element matching the given CSS selector.

In old Firebug versions, this used to be equivalent to document.getElementById.

$$(selector)

Returns an array of elements that match the given CSS selector.

$x(xpath)

Returns an array of elements that match the given XPath expression.

$0

Represents the last element selected via the Inspector.

$1

Represents the second last element selected via the Inspector.

$_

Returns the value of the most recently evaluated expression in the Command Line.

$p

A container of arbitrary JavaScript values, after right-clicking them and selecting "Use in Command Line".

$n(index)

Returns one of the 5 last elements selected via the Inspector. This method takes one required parameter index, which represents the index of the element (starting at 0).

dir(object)

Prints an interactive listing of all properties of the object. This looks identical to the view that inside the DOM Panel.

dirxml(node)

Prints the XML source tree of an HTML or XML element. This looks identical to the view inside the HTML Panel. You can click on any node to inspect it in the HTML panel.

cd(window)

By default, command line expressions are relative to the top-level window of the page. cd() allows you to use the window of a frame in the page instead.

clear()

Clears the console.

copy(object)

Copies the given parameter to the clipboard. This can be a return value of a function or an object.

inspect(object[, panelName])

Inspects an object in the most suitable panel, or the panel identified by the optional argument panelName.

The available tab names are "html", "stylesheet", "script", and "dom".

keys(object)

Returns an array containing the names of all properties of the object.

values(object)

Returns an array containing the values of all properties of the object.

include(url[, alias]) / include(alias)

Includes a remote script.

debug(fn)

Adds a breakpoint on the first line of a function.

undebug(fn)

Removes the breakpoint on the first line of a function.

monitor(fn)

Turns on logging for all calls to a function.

unmonitor(fn)

Turns off logging for all calls to a function.

monitorEvents(object[, types])

Turns on logging for all events dispatched to an object. The optional argument types may define specific events or event types to log.

unmonitorEvents(object[, types])

Turns off logging for all events dispatched to an object. The optional argument types may define specific events or event families, for which to turn logging off.

For a list of available event families see monitorEvents(object[, types]).

profile([title])

Turns on the JavaScript profiler. The optional argument title contains the text to be printed in the header of the profile report.

profileEnd()

Turns off the JavaScript profiler and prints its report.

table(data[, columns])

This is a shortcut for console.table().

traceCalls(fn)

Enables tracing of specific function calls.

untraceCalls(fn)

Disables tracing of specific function calls.

traceAll()

Enables tracing of function calls for a whole context.

untraceAll()

Disables tracing of function calls for a whole context.

getEventListeners()

Returns all the event listeners registered for specific node (event target).

Personal tools