JavaScript

Chrome devtools: Using logpoints for logging messages directly

Advertisements

When it comes to debugging JavaScript in Chrome devtools, there are two different camps: the console.log fans and the debugger/breakpoint maximalist. I often switch between the two depending on what problem I am tackling. There is a third option that is kind of in the middle. Logpoints provide us with a breakpoint-like mechanism that logs variables instead of halting the execution.

How to add a logpoint

  1. Open devtools
  2. Right click the line at which you want to add the logpoint
  3. Provide the message as well as any variables that you want to be logged

All variables that are present in the current context can be logged using this.

Here’s a video for the steps:

This is particularly useful when dealing with third-party scripts which you cannot modify using your source code. Plus it saves a bunch of console.log/debugger cleanup once you are done debugging.

And that is it for this quick tutorial! Hope you found this tip useful and will start using more of it in your day-to-day debugging. Happy coding!

Saransh Kataria

Born in Delhi, India, Saransh Kataria is the brain behind Wisdom Geek. Currently, Saransh is a software developer at a reputed firm in Austin, and he likes playing with new technologies to explore different possibilities. He holds an engineering degree in Computer Science. He also shares his passion for sharing knowledge as the community lead at Facebook Developer Circle Delhi, NCR which is a developer community in Delhi, India.

Share
Published by
Saransh Kataria

Recent Posts

Remapping keyboard keys to avoid Carpal Tunnel

I am terrible at optimizing my keyboard layout for anything. But off lately, my little…

3 weeks ago

Fixing cookies are blocked for a website with shields down on Brave

I recently switched completely to the Brave browser and have set ad blocking to aggressive…

5 months ago

Generating a QR code using Node.js

I was preparing a slide deck for a hackathon and decided to put in a…

6 months ago

How to clear the global npx cache

I have been using npx a lot lately, especially whenever I want to use a…

6 months ago

Copy/Pasting output from the terminal

Manually copy-pasting the output of a terminal command with a mouse/trackpad feels tedious. It is…

7 months ago

How To Get The Hash of A File In Node.js

While working on a project, I wanted to do an integrity check of a file…

7 months ago
Advertisements