You can interpret JavaScript expressions in real time using the command line provided by the Web Console.

Entering expressions

To enter expressions just type on the command line and press Enter. To enter multiline expressions, use Shift+Enter instead of Enter.

The expression you type is echoed in the message display window, followed by the result:

Console output showing syntax highlighting

If your input does not appear to be complete when you press Enter, then the Console treats this as Shift+Enter , enabling you to finish your input.

For example, if you type:

function foo() {

and then Enter, the Console will not immediately execute the input, but will behave as if you had pressed Shift+Enter , so you can finish entering the function definition.

Accessing variables

You can access variables defined in the page, both built-in variables like window and variables added by JavaScript like jQuery:


The command line has autocomplete: enter the first few letters and a popup appears with possible completions:

Type Enter, Tab, or the right arrow key to accept the suggestion, use the up/down arrows to move to a different suggestion, or just keep typing if you don't like any of the suggestions.

Console autocomplete suggestions are case-insensitive.

The console suggests completions from the scope of the currently executing stack frame. This means that if you've hit a breakpoint in a function you get autocomplete for objects local to the function.

You get autocomplete suggestions for array elements, as well:

Defining variables

You can define your own variables and functions, and then access them:

Console output showing syntax highlighting

The text you enter will have syntax highlighting, once it has been interpreted, and the output will be as well where appropriate.

Note: Syntax highlighting will not be visible in your browser if Accessibility features have been enabled.

Command history

The command line remembers commands you've typed: to move back and forward through your history, use the up and down arrows.

The command history is persisted across sessions. To clear the history, use the clearHistory() helper function.

Starting with Firefox 65, you can initiate a reverse search through the command line history, much like you can in bash on Linux and Mac or PowerShell on Windows.

On Windows and Linux press F9, on Mac press Ctrl + R to initiate the reverse search.

Enter the text you want to search for in the input box at the bottom of the Console. Start typing the command you are looking for and the first match will be displayed in the console. Repeatedly typing Ctrl + R (F9 on Windows and Linux) will cycle backwards through the matches.

Once you  have initiated the reverse search, you can use Ctrl + S (Shift + F9 on Windows or Linux) to search forward in the list of matches. When you find the command you want, press Return (Enter) to execute the statement.

Working with iframes

If a page contains embedded iframes, you can use the cd() command to change the console's scope to a specific iframe, and then you can execute functions defined in the document hosted by that iframe. There are three ways to select an iframe using cd():

You can pass the iframe DOM element:

var frame = document.getElementById("frame1");

You can pass a CSS selector that matches the iframe:


You can pass the iframe's global window object:

var frame = document.getElementById("frame1");

To switch the context back to the top-level window, call cd() with no arguments:


For example, suppose we have a document that embeds an iframe:

<!DOCTYPE html>
    <meta charset="UTF-8">
    <iframe id="frame1" src="static/frame/my-frame1.html"></iframe>

The iframe defines a new function:

<!DOCTYPE html>
    <meta charset="UTF-8">
      function whoAreYou() {
        return "I'm frame1";

You can switch context to the iframe like this:


Now you'll see that the global window's document is the iframe:

And you can call the function defined in the iframe:

Helper commands

The JavaScript command line provided by the Web Console offers a few built-in helper functions that make certain tasks easier.

$(selector, element)

Looks up a CSS selector string selector , returning the first node descended from element that matches. If unspecified, element defaults to document. Equivalent to document.querySelector() or calls the $ function in the page, if it exists.

See the QuerySelector code snippet.

$$(selector, element)
Looks up a CSS selector string selector, returning an array of DOM nodes descended from element that match. If unspecified, element defaults to document. This is like for document.querySelectorAll(), but returns an array instead of a NodeList.
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)
Evaluates the XPath xpath expression in the context of element and returns an array of matching nodes. If unspecified, element defaults to document
Given an object, returns a list of the keys (or property names) on that object. This is a shortcut for Object.keys.
Given an object, returns a list of the values on that object; serves as a companion to keys().
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
:helpRequires Gecko 62
Displays help text. Actually, in a delightful example of recursion, it will bring you to this page.

Switch JavaScript evaluation context to a different iframe in the page. This helper accepts multiple different ways of identifying the frame to switch to. You can supply any of the following:

  • a selector string that will be passed to document.querySelector to locate the iframe element
  • the iframe element itself
  • the content window inside the iframe

See working with iframes.

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 outerHTML is copied. Otherwise, JSON.stringify will 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

The command has the following optional parameters:
Command Type Description
--clipboard boolean When present, this parameter will cause the screenshot to be copied to the clipboard.
--delay number The number of seconds to delay before taking the screenshot.
--dpr number The device pixel ratio to use when taking the screenshot.
--file boolean When present, the screenshot will be saved to a file, even if other options (e.g. --clipboard) are included.
--filename string The name to use in saving the file. The file should have a ".png" extension.
--fullpage 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.
--selector 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.

Document Tags and Contributors

Contributors to this page: irenesmith, mdnwebdocs-bot, nchevobbe, ExE-Boss, wbamberg, Nickolay
Last updated by: irenesmith,