A window into your code
The primary use for the Console tool is to communicate into and out of running webpages.
Messages Microsoft Edge sends to the console
The Console has three categories:
- Error: Critical errors that cause code not to run. For more info, see a list of error codes used in the console.
- Warning: Possible errors in your webpage that don't necessarily break it, but may cause unexpected behavior.
- Information: Non-critical information you might want to know.
These messages can be filtered out of the Console output. The icons for each message type at the top of the Console pane act as toggles. Click one to remove its associated message type, then again to return it. You can also right-click in the Console output and find check boxes for each type in the context menu.
When you click the file name that follows a message, you open the Debugger tool and load the file in the script pane.
When the Clear on navigate icon is highlighted, the console clears every time the browser navigates to a new webpage (including refresh). When it isn't highlighted, the browser preserves the contents of the Console, but messages from prior webpages are grayed out to better visually indicate they are not from the current page.
Selecting your execution target
The Console has a Target drop-down menu just above the Console output pane. If the webpage you're viewing has an [iframe element]() in it, select the iframe from the Target menu to run Console commands solely in the scope of the iframe. If your webpage has no iframes, the only selection will be "_top."
In the image above, the Target iframe is selected, then the page reloads to output only Error messages. The file name is then clicked to follow the error to the script file where it is located in the Debugger. Returning to the Console, the Error Code itself is clicked, opening the documentation page for that error code.
Generally, all script entered in the command line executes in the global scope of the currently selected window. However, if your script is currently paused (for instance, because you set a breakpoint), script executes in the local scope of the current function within the call stack.
To target the window of a frameset frame or an iframe, select the frame you want to target in the Target dropdown to the right of the console filter icons.
Selecting elements in the Console
Console selectors provide simple shorthands for quickly selecting elements in your DOM structure. They are:
- $() is a shorthand for
- $$() is a shorthand for
- $_() is a shorthand for the last selected element or object.
- $0, $1, $2, $3, $4 return the last items selected in the DOM Explorer tool.
Important If code in a webpage assigns a function to $ or $$, that function overrides the console selector functions while the console is interacting with that page or its frames.
The multiline command line
Sending in single line commands is useful, but some tasks require executing longer scripts. Click the double up-arrow symbol (
Ctrl+Shift+M) to expand the command line. In multiline mode, enter as many lines as you need, then click the green arrow symbol to execute it in the console (
Ctrl+Enter). You can also clear the script by clicking the clear symbol (