The Web Console:
It's part of the replacement for the old Error Console built into Firefox: but the Error Console showed errors, warnings, and messages from all web pages, from the browser's own code, and from add-ons. This makes it much more difficult to see which messages are relevant to a specific page. The Web Console is always associated with a specific web page and only shows information associated with that page.
The other half of the replacement for the Error console is the Browser Console, which shows errors, warnings, and messages from the browser's code and from add-ons.
Opening the Web Console
To open the Web Console select "Web Console" from the Web Developer submenu in the Firefox Menu (or Tools menu if you display the menu bar or are on Mac OS X), or by pressing its Control-Shift-K (Command-Option-K on the Mac) keyboard shortcut.
Underneath the DevTools Window's own toolbar, the Web Console's interface is split into three sections:
- Toolbar: along the top is a toolbar containing buttons with labels like "Net", "CSS", and "JS". This toolbar is used to filter which messages are displayed
- Message Display Pane: in between the toolbar and the command line, and occupying most of the window, is the space in which the Web Console displays messages
Most of the Web Console is occupied by the message display pane:
The message display pane displays the following sorts of messages:
- HTTP requests
- Input/output messages: commands send to the browser via the Web Console's command line, and the result of executing them.
Each message is displayed as a single row in the pane.
HTTP requests are logged with a line that looks like this:
- Time: the time the message was recorded
- Category: this indicates that the message is an HTTP request
- Method: the specific HTTP request method
- URI: the target URI
- Summary: the HTTP version, status code, and time taken to complete
By default, the Web Console does not log request and response bodies: to do this, activate the context menu in the Web Console and select "Log Request and Response Bodies".
If you click on the message, you'll see a window like this, containing more details about the request and response:
Scrolling down reveals the response headers. By default, the Web Console does not log request and response bodies: to do this, activate the context menu in the Web Console and select "Log Request and Response Bodies", reload the page, and you'll then see them in the "Inspect Network Request" window.
Only the first megabyte of data is logged for each request or response body, so very large requests and responses will be truncated.
Warnings and errors
Warnings and errors are logged with a line looking something like this:
- Time: the time the message was recorded
- Category: this indicates what sort of message this is:
- Blue: CSS warning/error
- Red: security warning/error
- Type: an icon indicating whether it is an error(☓) or a warning(⚠).
- Message: the message itself
- Number of occurrences: if a line that generates a warning or error is executed more than once, it is only logged once, and this counter appears to indicate how many times it was encountered.
- Filename and line number: a link to the filename and line number that generated the message
Reflow events are only logged from Firefox Desktop 27+ and Firefox OS 1.3+.
Reflow events are logged under the CSS category, as "Log" messages, as distinct from CSS errors or warnings. By default, they are disabled. You can enable them by clicking the "CSS" button in the toolbar and selecting "Log".
Each message is labeled "reflow" and shows the time taken to execute the reflow:
Click the link to open the file in the Debugger.
var thing = document.getElementById("the-thing"); thing.style.display = "inline-block"; var thingHeight = window.getComputedStyle(thing).height;
Because of this, it's a good idea to avoid interleaving write and read calls to an element's styles when manipulating the DOM, because every time you read back a style that has been invalidated by a previous write call, you force a synchronous reflow.
Commands sent to the browser using the Web Console's command line, and the corresponding responses, are logged using lines like this:
The dark gray bar indicates that these are input/output messages, while the direction of the arrow discriminates between input and output.
You can use the toolbar along the top to constrain the results displayed.
You can display only specific types of messages or only message containing specific strings.
Finally, you can use this toolbar to clear the log.
To enter expressions just type into 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:
You can access variables defined in the page, both built-in variables like
The command line has autocomplete: enter the first few letters and a popup appears with possible completions:
Type "Enter" or "Tab" 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.
If the result object is an object it appears in square brackets and is underlined, like this:
[object Function]. Click on it, and you'll see a new panel appear containing details of the object:
To dismiss this panel press "Escape".
You can define your own variables, and then access them:
The command line remembers commands you've typed: to move back and forward through your history, use the up and down arrows.
|↑||Moves to the previous entry in the command history, or, if an autocomplete popup is open, highlights the previous suggestion.|
|↓||Moves to the next entry in the command history, or, if an autocomplete popup is open, highlights the next suggestion.|
|Ctrl-A||Moves the cursor to the beginning of the line. (Note: beginning with Firefox 22, this will select all text on Windows)|
|Ctrl-E||Moves the cursor to the end of the line.|
|Return||Executes the code typed on the command line, or, if an autocomplete popup is open, chooses the current suggestion.|
|Shift-Return||Expands the height of the text input box for the command line by a line.|
|Escape||Cancels the autocompletion popup.|
|Tab||Generates an autocomplete suggestion and accepts the first one.|
Looks up a CSS selector string, returning the first element that matches. Equivalent to
document.querySelector()or calls the $ function in the page, if it exists.
Looks up a CSS selector string, returning a list of DOM nodes that match. This is a shortcut for
- The currently-inspected element in the page.
- Evaluate an Xpath expression and return an array of matching nodes.
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.
- Displays help text. Actually, in a delightful example of recursion, it will bring you to this page.
- Please refer to the Console API for more information about logging from content.