Chrome devTools Logo

Leveling up Front-end debugging by mastering Chrome DevTools

Paul Rosset
6 min readAug 14, 2023

Every software developer knows some tools can significantly elevate their coding prowess. Among these, mastering the art of debugging stands out as paramount. Fine-tune this skill, and you’ll solve problems faster and ascend to the ranks of top-tier developers.

In this guide, we’ll delve deep into the robust debugging features of Chrome DevTools. While Chrome offers many tools, some remain hidden gems, often overlooked until someone shines a light on them.

This blog post will cover those I use daily to be more productive.

Throttling the Network

Ever wondered how your app performs under poor network conditions? Chrome DevTools provides a stellar feature for that exact purpose, allowing you to simulate real-world connectivity scenarios.

Here’s how to access it:

  1. Navigate to the Network tab.
  2. Adjacent to “Disable cache,” you’ll spot “No throttling.” This is a dropdown menu. Clicking on it reveals a slew of options.
Chrome DevTools Network tab

Several predefined settings like “Slow 3G” or “Offline” allow you to emulate conditions that users might face in real-world situations. This helps you test the resilience of your app’s loading schemes and is invaluable for examining streaming-related code, such as the adaptive bitrate algorithms akin to those of Netflix.

Moreover, you can craft custom network condition profiles if the built-in options don’t cater to your specific needs.

Throttling network inside Chrome DevTools

A word to the wise: Chrome provides a visual heads-up when throttling is activated by appending a discreet warning indicator to the Network tab.

When throttling is activated Chrome warn you

Always remember to check for active throttling — it’ll save you from potential mix-ups, especially if you find yourself without the internet or grappling with a sluggish connection.

Trigger Hover and CSS pseudo-class

Here’s a straightforward tip to streamline your debugging and development process, especially when working with hover, focus, or active animations.

In Chrome DevTools, select an HTML element in the DOM with a pseudo-class. Then click on :hov and choose the desired pseudo-class. This lets you manually activate a specific state without the usual real-world interaction with the DOM element, mimicking what a user might experience.

Chrome DevTools styles Forcing element state

User-agent simulator

When developing within a browser, common wisdom warns against relying too heavily on User-Agent variables to determine a state. Why? User-Agent information can be manipulated, allowing someone to impersonate or ‘fake’ a user agent.

The good news is that Chrome DevTools allows you to experiment with this yourself. Whether you’re testing compatibility or exploring other scenarios, here’s how you can modify the User-Agent within Chrome DevTools:

Changing User agent inside Chrome DevTools

That feature allows you to test your working piece of code if you added a specific code to handle a mobile device based on the User-agent.

Blocking XHR Request

One of Chrome DevTools’ standout features, which I adore, is the ability to block HTTP request requests. This capability proves invaluable when you’re aiming to test how your application responds to error scenarios.

Furthermore, this feature is a game-changer if you’re reverse-engineering a website and wish to halt a specific tracking HTTP.

Want to see how it works? Check out the quick video tutorial above.

Blocking an HTTP Request inside Chrome DevTools

Debugging on silent exception

In your code or a third-party import, silent errors can creep in. These errors might be suppressed due to exception handling, creating deceptive stability. While preempting and managing catastrophic errors is commendable, poor implementation can turn your debugging journey into a perplexing maze, especially as your application scales.

Chrome DevTools comes to the rescue with the debugger keyword, adept at detecting these caught exceptions.

Pause on caught exceptions

With this, any exception trapped during your application’s runtime will automatically activate a breakpoint.

However, a word of caution: If you’re integrating several external scripts and enabling this debugging feature early in your application’s lifecycle, be prepared to navigate numerous breakpoints. It might lengthen your quest for the real culprit, requiring you to sift through potential breakpoints individually.

Search and debugging

While debugging with a local copy offers precision, it often translates into a time sink. Imagine constantly setting manual breakpoints, recompiling, and refreshing your local setup at every step. Sounds tedious, doesn’t it?

With the Search feature in DevTools, you can pinpoint the problematic statement directly, saving precious minutes (or even hours). Before diving in, remember to switch to development mode—this ensures the code remains unminified. If it's minified, finding the exact piece of code becomes an easier task.

Search and debug option in Chrome DevTools

The result? Efficient, real-time debugging, all consolidated within DevTools. Your workflow just got exponentially faster!

Javascript Bookmarks

Let’s pivot to a lesser-known yet powerful tool: Javascript Bookmarklets. This feature deserves more recognition, especially for those keen on embedding javascript and automating tasks. Chrome’s Bookmarklet functionality allows you to run Javascript code directly in the context of a webpage.

You might be thinking, “Aren’t bookmarklets just for saving links for later?” While that’s everyday use, Chrome’s Bookmarklet feature steps it up a notch. It enables you to execute Javascript simply by clicking on the bookmark.

You can head to chrome://bookmarks/ and click right to create a new bookmark.

Here’s how you can create your own:

  1. Navigate to chrome://bookmarks/.
  2. Right-click to create a new bookmark.
  3. For the name, choose any descriptive title.
  4. Instead of adding a regular link in the URL field, enter a javascript statement prefixed by the javascript: keyword.

For example, if you want to instantly Google search the current date, use:

javascript:window.location='[<https://www.google.com/search?q='+Date()>](<http://www.google.com/search?q=%27+Date()>)

This is especially handy when you want to tweak a website’s behavior. Instead of manually running scripts each time, a simple click can do the trick.

A true timesaver for those in the know.

Requestly to go further…

Bookmarks can sometimes fall short. That’s where Requestly comes into play.

Requestly is a Chrome extension designed to manage client and server network interactions. It’s versatile, catering to a variety of tasks. For example, it allows you to test your client’s operations using local source files instead of relying on JavaScript files on a remote production server.

Furthermore, it provides a fine-tuned control to block specific HTTP requests. At its core, Requestly utilizes the Chrome network API for extension development. Learn more here.

Personally, Requestly has enhanced my debugging and development process multiple times.”

Conclusion

Debugging is an indispensable component of a developer’s toolkit, and often, the time we invest in debugging can surpass the time spent crafting the initial code. This fact underscores the profound importance of honing our debugging skills.

By mastering Chrome DevTools, not only do we enhance the quality of the code we write, but we also significantly reduce the time spent diagnosing issues. Consider this: if you can expedite the process of reproducing an issue, you inevitably save valuable hours, enabling you to allocate that time elsewhere.

In wrapping up, I hope this article has enlightened you with fresh debugging perspectives and methods. May the insights shared here empower you to tackle your next debugging challenge at work with renewed efficiency.

--

--

Paul Rosset

Former Software developer Player C+, Qonto, CrowdStrike. Do things with passion! me.paulrossethings.com