Step-through debugging is the process of adding breakpoints to your code. The next time that line of code is executed, the browser will pause the execution so you can explore the application at that state in time. One of the most exciting things about Replay is that it captures the entire session. Usually, from a browser breakpoint, you can only step forward. But with a Replay, you can step back and forth as you please! This is called time travel debugging.

Adding breakpoints

To add a breakpoint, go to a Replay and click on the DevTools tab. From there, you can use the Sources pane in the middle to find a source file by either filename or function name.

You can use the following keyboard shortcuts to navigate the source editor:

Once inside a source file, you can hover over a line number to see how many times that line was executed. You can also click on a line number to add a breakpoint.

Once you've added a breakpoint, Replay will automatically jump to that point in time and pause the application. If the line was executed multiple times, the [scrubber] below allows you to jump between them quickly. You can also add a comment to the breakpoint or even double-click on the line to add a custom print statement or a conditional.

Conditional breakpoints

Sometimes we want to put a breakpoint in a function that gets called multiple times. But we only want to pause if a certain condition is met. Think of the example below:

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/9b00fc5a-bb4f-4d74-b7cb-3fccae162af2/Screen_Shot_2021-06-29_at_7.22.10_PM.png

We have a log function that gets called 101 times. What would we do if we wanted to only see the log message associated with "critical" logs? This is where conditional breakpoints come in!

We can double click on the log and add a condition. Since we know that logLevels.critical resolves to the number 2, we can add the condition level === 2 and get the following!

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/a60566c7-4658-43e7-ba78-c0090c472739/Screen_Shot_2021-06-29_at_7.24.12_PM.png

We just used conditional breakpoints to reduce the number of pauses from 101 to 1! Now it's easy to check the console and find our message.

Try using conditional breakpoints in the Replay itself. See if you can find the message that the critical log statement sends without looking at the code!

Stepping around