7 Useful Features of Chrome DevTools
Tags: webdev, chrome, devtools, debug
Published: 2020-07-25 21:35:18

## Preserve Log

Imagine you have a bug that causes a page to reload. Every time the bug gets triggered you lose all your logs and have no idea where to start debugging.

This function maintains a record of logs in the Console even after reloading. Go to Settings and then check "Preserve Logs" to activate it.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/cl6n583rvpilo8ov6tq2.gif)

*Tip: Run Clear console (Ctrl + L or Cmd + K) when you’re done debugging.*
<p>&nbsp;</p>

## Debug on DOM Modifications

There are situations where you want to notice changes on a specific element to inspect what’s happening. To trigger a break when a DOM element changes, right-click on an element and then select one of the next:

**Subtree modifications:** Breaks when a script modifies the selected element’s children.

**Attribute modifications:** Breaks when an attribute is added to the selected element.

**Node removal:** Breaks when the selected element is removed.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/dzi8fl28f8zxah5szdq5.png)
<p>&nbsp;</p>

## Screenshots

Taking a screenshot using DevTools is quicker than opening an external application to capture your screen, especially when you can choose between capturing a selected area, full-size page, a specific node, or just your viewport.

Access this menu using Ctrl + Shift + P (or Cmd + Shift + P in Mac), then type “Screenshot” and select your desired option. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/vuhl92lv82kfrfv5w7tj.png)
<p>&nbsp;</p>

## Reference a selected element in the Console 

In the Elements tab, select an element you want to reference in the Console, then go back to the Console tab and type $0. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/sss5q5b58t5hok8v7uhw.gif)
<p>&nbsp;</p>

## Show Rendering

It is helpful to look at what is rendering when we interact with our page, particularly when looking at performance issues. To highlight changes in the DOM we can go to Console, bring the tools bar using Ctrl + Shift + P (or Cmd + Shift + P in Mac) and then search for Show Rendering. Make sure to select the checkbox in the Rendering tab that activates Paint flashing. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/x4dwi1fpnkxrlqfkeh5m.gif)
<p>&nbsp;</p>

## Use Console Functions

Sometimes we could overuse console.log() to debug when there might be other useful functions for specific purposes inside the Console class. 

For example, when logging an array of objects it can be useful to visualize this as a table. Use console.table() to visualize your data this way.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/7n88yedm3emfwpa80e1z.png)
<p>&nbsp;</p>

There are also different types of logs that we can use to prioritize issues like warning, error, and info.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/8avbp05z6089qm96m8vu.png)
<p>&nbsp;</p>

You can then use the dropdown “Default levels” next to the filter box to filter between different types of logs.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/jtqpmd6m1ju25jxp1ck3.png)
<p>&nbsp;</p>

## copy(object)

This function allows you to copy anything into the clipboard. It is particularly useful when giving it a JSON object as it will copy a prettified version of your JSON into the clipboard. 

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/q7zzupf2nqawv802p005.png)
<p>&nbsp;</p>

You can also give this function an HTML element and it will copy it (and their children, if they do have any!)

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/lhkrmvy7ejt1j0pynefz.png)
<p>&nbsp;</p>


DevTools has many other options that can help your productivity, for more information check out [Chrome DevTools official documentation](https://developers.google.com/web/tools/chrome-devtools) or [Chrome DevTools Twitter account](https://twitter.com/chromedevtools) for new updates and tips.