| title | Monitor changes in JavaScript using Live Expressions |
|---|---|
| description | Watch JavaScript expression values in real time with Live Expressions. If you find yourself typing the same JavaScript expressions into the Console tool repeatedly, try Live Expressions instead. |
| author | MSEdgeTeam |
| ms.author | msedgedevrel |
| ms.topic | conceptual |
| ms.prod | microsoft-edge |
| ms.date | 04/13/2021 |
Live Expressions are a great way to monitor JavaScript expressions that change a lot. Instead of generating many Console messages to read and navigate, you can pin your specific JavaScript expressions to the top of the Console.
To add a live expression:
-
Open the accessibility-testing demo webpage in a new window or tab.
-
Right-click anywhere in the webpage and then select Inspect. Or, press
F12. DevTools opens next to the webpage. -
In DevTools, open the Console.
-
In the Console, click the Create live expression (
) icon next to the Filter text box.A text box opens:
-
Enter the JavaScript expression
document.activeElementinto the text box. A Live Expression can be any valid JavaScript expression. -
To save the expression, press
Ctrl+Enter(Windows, Linux) orCommand+Enter(macOS). Or, click outside of the Live Expression text box.The expression is now live, and displays
bodyas the result: -
Click different parts of the webpage, or press
TabandShift+Tabto move around in the webpage, thedocument.activeElementLive Expression value changes.In the accessibility-testing demo webpage, when you
Tabto put focus on the Other text box in the Donation section, the Live Expression value readsinput#freedonation.smallinput. -
In that same window, go to the webpage Overview of DevTools, and then click the Docs button in the upper left.
The Live Expression value changes to
button.nav-bar-button.focus-visible: -
To change the value again, open and click the Search text box on the webpage.
The Live Expression value changes to
input#site-search-input.autocomplete-input.input.is-small.focus-visible:
A Live Expression is available as long as you keep it active.
You can create as many Live Expressions as you want, and persist each Live Expression across browser sessions and windows. Live Expressions are a way to cut down on noise in your debugging workflow.
To monitor the mouse movement in the current webpage:
-
Open the demo webpage Logging Mouse Movement demo in a new window or tab.
-
Press
Ctrl+Shift+J(Windows, Linux) orCommand+Option+J(macOS). The Console tool opens in DevTools, next to the demo webpage. -
Move your mouse around over the rendered demo webpage.
Many log messages are output, displayed in the Console:
The large amount of information slows down your debugging process, and makes it hard to see the changes that you're trying to monitor. As the Console displays more messages when you move your mouse, the values that you want to see scroll off the screen.
Use Live Expressions to monitor the mouse movement in the current webpage, without relying on verbose log messages.
To use Live Expressions to avoid excessive Console log messages:
-
Open the demo webpage Mouse movement without logging demo in a new window or tab.
-
Press
Ctrl+Shift+J(Windows, Linux) orCommand+Option+J(macOS). The Console tool opens in DevTools, next to the demo webpage. -
Move your mouse around. No log messages are output.
Enter two Live Expressions: the expression
x, and the expressiony, as follows: -
In the Console tool, click the Create live expression (
) icon next to the Filter text box. -
Enter the JavaScript expression
xinto the text box, and then click outside of the Live Expression text box. Repeat fory. If needed, see Add a new live expression, above. -
Move your mouse around.
Now in the DevTools Console, the Live Expression value is updated, below the Live Expression, showing the
xandycoordinates of the mouse:
When you use Live Expressions, you always get the information on the same part of your screen, and keep Console logs for values that don't change as much.
Live Expressions run exclusively on your computer, and you don't need to change anything in your code to display the expression and its result. Live Expressions are a great way to ensure that you only display the information that you want to debug. Live Expressions also help you limit the noise on your users' computers.






