This translation is incomplete. Please help translate this article from English
Looks up a CSS selector string
selector, returning the first node descended from
elementthat matches. If unspecified,
document. Equivalent to
document.querySelector()or calls the $ function in the page, if it exists.
See the QuerySelector code snippet.
- Looks up a CSS selector string
selector, returning an array of DOM nodes descended from
elementthat match. If unspecified,
document. This is like for
document.querySelectorAll(), but returns an array instead of a
- The currently-inspected element in the page.
- Stores the result of the last expression executed in the console's command line. For example, if you type "2+2 <enter>", then "$_ <enter>", the console will print 4.
$x(xpath, element, resultType)
- Evaluates the XPath
xpathexpression in the context of
elementand returns an array of matching nodes. If unspecified,
document. The resultType parameter specifies the type of result to return; it can be an XPathResult constant, or a corresponding string:
"nodes"; if not provided,
- Given an object, returns a list of the keys (or property names) on that object. This is a shortcut for
- Given an object, returns a list of the values on that object; serves as a companion to
- Clears the console output area.
- Given an object, opens the object inspector for that object.
- Formats the specified value in a readable way; this is useful for dumping the contents of objects and arrays.
help()Deprecated since Gecko 62
- Displays help text. Actually, in a delightful example of recursion, it will bring you to this page.
- a selector string that will be passed to
document.querySelectorto locate the iframe element
- the iframe element itself
- the content window inside the iframe
See working with iframes.
- a selector string that will be passed to
- New in Firefox 38. Copy the argument to the clipboard. If the argument is a string, it's copied as-is. If the argument is a DOM node, its
outerHTMLis copied. Otherwise,
JSON.stringifywill be called on the argument, and the result will be copied to the clipboard.
- New in Firefox 39. Just like a normal command line, the console command line remembers the commands you've typed. Use this function to clear the console's command history.
- New in Firefox 62. Create a screenshot of the current page with the supplied filename. If you don't supply a filename, the image file will be named:
Screen Shot yyy-mm-dd at hh.mm.ss.png
The command has the following optional parameters:
Comando Tipo Descrição
boolean When present, this parameter will cause the screenshot to be copied to the clipboard.
number The number of seconds to delay before taking the screenshot.
number The device pixel ratio to use when taking the screenshot.
boolean When present, the screenshot will be saved to a file, even if other options (e.g.
--clipboard) are included.
string The name to use in saving the file. The file should have a ".png" extension.
boolean If included, the full webpage will be saved. With this parameter, even the parts of the webpage which are outside the current bounds of the window will be included in the screenshot. When used, "-fullpage" will be appended to the file name.
string The CSS query selector for a single element on the page. When supplied, only this element will be included in the screenshot.
Please refer to the Console API for more information about logging from content.
- The "Use in Console" option in the Inspector generates a variable for a node named
temp2, etc. referencing the node.
Looking at the contents of a DOM node
Let's say you have a DOM node with the ID "title". In fact, this page you're reading right now has one, so you can open up the Web Console and try this right now.
Let's take a look at the contents of that node by using the
This automatically opens up the object inspector, showing you the contents of the DOM node that matches the CSS selector "#title", which is of course the element with ID "title".
Dumping the contents of a DOM node
That's well and good if you happen to be sitting at the browser exhibiting some problem, but let's say you're debugging remotely for a user, and need a look at the contents of a node. You can have your user open up the Web Console and dump the contents of the node into the log, then copy and paste it into an email to you, using the
This spews out the contents of the node so you can take a look. Of course, this may be more useful with other objects than a DOM node, but you get the idea.