Command Line API
From FirebugWiki
Sebastianz (Talk | contribs) m (Added 'table' command) |
Sebastianz (Talk | contribs) (Improved description of some functions, added the 'copy' function and internal links) |
||
| Line 2: | Line 2: | ||
=== $(id) === | === $(id) === | ||
| - | |||
Returns a single element with the given id. | Returns a single element with the given id. | ||
| Line 12: | Line 11: | ||
=== $0 === | === $0 === | ||
| - | + | Represents the last element selected via the [[Inspector]]. | |
=== $1 === | === $1 === | ||
| - | + | Represents the second last element selected via the [[Inspector]]. | |
=== $n(index) === | === $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). | |
=== dir(object) === | === dir(object) === | ||
| - | Prints an interactive listing of all properties of the object. | + | Prints an interactive listing of all properties of the object. This looks identical to the view that inside the [[DOM Panel]]. |
=== dirxml(node) === | === dirxml(node) === | ||
| - | Prints the XML source tree of an HTML or XML element. | + | 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) === | === 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. | 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. | ||
| Line 33: | Line 31: | ||
Clears the console. | Clears the console. | ||
| - | === | + | === copy(object) === |
| - | + | Copies the given parameter to the clipboard. This can be a return value of a function or an object. | |
| - | The available tab names are "html", " | + | === inspect(object[, panelName]) === |
| + | Inspects an object in the most suitable panel, or the panel identified by the optional argument <code>panelName</code>. | ||
| + | |||
| + | The available tab names are "html", "stylesheet", "script", and "dom". | ||
=== keys(object) === | === keys(object) === | ||
| Line 51: | Line 52: | ||
=== monitor(fn) === | === monitor(fn) === | ||
| - | |||
Turns on logging for all calls to a function. | Turns on logging for all calls to a function. | ||
| Line 58: | Line 58: | ||
=== monitorEvents(object[, types]) === | === monitorEvents(object[, types]) === | ||
| - | Turns on logging for all events dispatched to an object. The optional argument <code>types</code> may | + | 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. |
| - | ==== | + | ==== Event types ==== |
| - | < | + | {| class="wikitable" style="width:100%; vertical-align:top;" |
| - | + | |- bgcolor=lightgrey | |
| - | + | ! style="width:100px;" | Type || Included events in Firebug || Included events in Web Inspector | |
| - | + | |- | |
| - | + | | <code>composition</code> || <code>composition</code>, <code>compositionend</code>, <code>compositionstart</code> || - | |
| - | + | |- | |
| - | + | | <code>contextmenu</code> || <code>contextmenu</code> || - | |
| - | + | |- | |
| + | | <code>control</code> || - || <code>blur</code>, <code>change</code>, <code>focus</code>, <code>reset</code>, <code>resize</code>, <code>scroll</code>, <code>select</code>, <code>submit</code>, <code>zoom</code> | ||
| + | |- | ||
| + | | <code>drag</code> || <code>dragdrop</code>, <code>dragenter</code>, <code>dragexit</code>, <code>draggesture</code>, <code>dragover</code> || - | ||
| + | |- | ||
| + | | <code>focus</code> || <code>blur</code>, <code>focus</code> || - | ||
| + | |- | ||
| + | | <code>form</code> || <code>change</code>, <code>input</code>, , <code>reset</code>, <code>select</code><code>submit</code> || - | ||
| + | |- | ||
| + | | <code>key</code> || <code>keydown</code>, <code>keypress</code>, <code>keyup</code> || <code>keydown</code>, <code>keypress</code>, <code>keyup</code>, <code>textInput</code> | ||
| + | |- | ||
| + | | <code>load</code> || <code>abort</code>, <code>beforeunload</code>, <code>error</code>, <code>load</code>, <code>unload</code> || - | ||
| + | |- | ||
| + | | <code>mouse</code> || <code>click</code>, <code>dblclick</code>, <code>mousedown</code>, <code>mousemove</code>, <code>mouseup</code>, <code>mouseout</code>, <code>mouseover</code> || <code>click</code>, <code>dblclick</code>, <code>mousedown</code>, <code>mousemove</code>, <code>mouseup</code>, <code>mouseout</code>, <code>mouseover</code>, <code>mousewheel</code> | ||
| + | |- | ||
| + | | <code>mutation</code> || <code>DOMSubtreeModified</code>, <code>DOMNodeInserted</code>, <code>DOMNodeRemoved</code>, <code>DOMNodeRemovedFromDocument</code>, <code>DOMNodeInsertedIntoDocument</code>, <code>DOMAttrModified</code>, <code>DOMCharacterDataModified</code> || - | ||
| + | |- | ||
| + | | <code>paint</code> || <code>paint</code>, <code>resize</code>, <code>scroll</code> || - | ||
| + | |- | ||
| + | | <code>scroll</code> || <code>overflow</code>, <code>underflow</code>, <code>overflowchanged</code> || - | ||
| + | |- | ||
| + | | <code>text</code> || <code>text</code> || - | ||
| + | |- | ||
| + | | <code>touch</code> || - || <code>touchcancel</code>, <code>touchend</code>, <code>touchmove</code>, <code>touchstart</code> | ||
| + | |- | ||
| + | | <code>ui</code> || <code>DOMActivate</code>, <code>DOMFocusIn</code>, <code>DOMFocusOut</code> || - | ||
| + | |- | ||
| + | | <code>xul</code> || <code>popupshowing</code>, <code>popupshown</code>, <code>popuphiding</code>, <code>popuphidden</code>, <code>close</code>, <code>command</code>, <code>broadcast</code>, <code>commandupdate</code> || - | ||
| + | |- | ||
| + | | <code>clipboard</code> || <code>cut</code>, <code>copy</code>, <code>paste</code> || - | ||
| + | |} | ||
=== unmonitorEvents(object[, types]) === | === unmonitorEvents(object[, types]) === | ||
| - | Turns off logging for all events dispatched to an object. | + | 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.28object.5B.2C_types.5D.29|monitorEvents(object[, types])]]. | ||
=== profile([title]) === | === profile([title]) === | ||
| - | Turns on the JavaScript profiler. | + | 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() === | ||
Revision as of 13:38, 4 July 2012
The Firebug Command Line provides these special functions for your convenience:
$(id)
Returns a single element with the given id.
$$(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.
$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.
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.
Event types
| Type | Included events in Firebug | Included events in Web Inspector |
|---|---|---|
composition | composition, compositionend, compositionstart | - |
contextmenu | contextmenu | - |
control | - | blur, change, focus, reset, resize, scroll, select, submit, zoom
|
drag | dragdrop, dragenter, dragexit, draggesture, dragover | - |
focus | blur, focus | - |
form | change, input, , reset, selectsubmit | - |
key | keydown, keypress, keyup | keydown, keypress, keyup, textInput
|
load | abort, beforeunload, error, load, unload | - |
mouse | click, dblclick, mousedown, mousemove, mouseup, mouseout, mouseover | click, dblclick, mousedown, mousemove, mouseup, mouseout, mouseover, mousewheel
|
mutation | DOMSubtreeModified, DOMNodeInserted, DOMNodeRemoved, DOMNodeRemovedFromDocument, DOMNodeInsertedIntoDocument, DOMAttrModified, DOMCharacterDataModified | - |
paint | paint, resize, scroll | - |
scroll | overflow, underflow, overflowchanged | - |
text | text | - |
touch | - | touchcancel, touchend, touchmove, touchstart
|
ui | DOMActivate, DOMFocusIn, DOMFocusOut | - |
xul | popupshowing, popupshown, popuphiding, popuphidden, close, command, broadcast, commandupdate | - |
clipboard | cut, copy, paste | - |
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().