Chrome DevTools Shortcut for Faster Debugging

Author

Reads 321

Chrome and Black Engine Display
Credit: pexels.com, Chrome and Black Engine Display

Chrome DevTools is a powerful tool for debugging and optimizing web applications, but it can be overwhelming to navigate, especially for beginners.

With the right shortcuts, you can speed up your debugging process and become more efficient.

The most basic shortcut is F12, which opens the DevTools panel in a new window.

This shortcut is a game-changer for anyone who spends a lot of time in the DevTools panel.

To inspect an element, simply right-click on it and select "Inspect" or use the shortcut Ctrl + Shift + I (Windows) or Cmd + Opt + I (Mac).

This shortcut saves you time and effort compared to navigating through the menu.

Opening DevTools

Opening DevTools is a breeze, especially with the right shortcuts.

You can open DevTools by pressing Command + Option + I on a Mac.

If you've used a panel recently, Command + Option + I will open that panel again.

Alternatively, you can use Command + Option + J to open the Console panel.

Command + Option + C will take you straight to the Elements panel.

Here's a quick reference guide to get you started:

Navigation and Inspection

Credit: youtube.com, 21+ Browser Dev Tools & Tips You Need To Know

Navigation and Inspection is a crucial part of using Chrome DevTools shortcuts.

You can navigate to the Elements panel by pressing Ctrl + Shift + E (Windows/Linux) or Cmd + Opt + E (Mac).

To inspect an element, click on it in the Elements panel, or use the Inspect Element shortcut, which is Ctrl + Shift + I (Windows/Linux) or Cmd + Opt + I (Mac).

Elements

Navigating the Elements panel can be a bit overwhelming, especially with all the keyboard shortcuts at your disposal. To start, you can use `command+z` to undo a change, or `command+shift+z` to redo a change.

One of the most useful shortcuts in the Elements panel is `up` or `down`, which allows you to select the element above or below the currently-selected element.

You can also use `right` to expand the currently-selected node, or `left` to collapse it. If the node is already expanded, `right` will select the element below it, while `left` will select the element above it.

Credit: youtube.com, 5 Cool Inspect Element Tips

Another useful trick is to hold `option` and click the arrow icon next to the element's name, which will expand or collapse the currently-selected node and all of its children.

If you're working with a lot of elements, you might appreciate the ability to toggle Edit Attributes mode on the currently-selected element by pressing `enter`.

Here are some common keyboard shortcuts for navigating the Elements panel:

Code Snippets

You can store and access frequently used JavaScript snippets in the "Snippets" pane, which is located among "Sources" and "Local Overrides" in Chrome DevTools.

The "Snippets" pane allows you to manage your code snippets from a dedicated area, similar to bookmarklets, but with more convenience and flexibility.

You can run a snippet by right-clicking and selecting "Run" or with Cmd/Ctrl + Enter, and each snippet is also available from the Command Panel.

You can use Code Snippets to automate routine tasks, such as cache busting, showing headers, or saving objects as .json files from the console.

The Snippets pane includes some useful scripts for displaying performance marks and other useful information, and you can also plug in a performance diagnostics CSS to indicate lazy-loaded images or unsized images.

You can modify the DOM or display any useful information, such as performance marks, using Code Snippets.

Dock States

Close-up view of a Facebook webpage interface in a browser window.
Credit: pexels.com, Close-up view of a Facebook webpage interface in a browser window.

To quickly switch between dock states, use Cmd/Ctrl + Shift + D. This shortcut works best if DevTools has been in its default position, docked to the right.

You can also highlight all instances that match a particular selector, which can be a huge time-saver when debugging. For example, if you notice a bug with rendering on dark and light sections of the page, you can highlight all instances of a particular class.

The Styles panel in DevTools is a great tool for this, and Firefox even goes a step further by explaining which CSS properties aren't affecting the selected element and why. This is called Inactive CSS, and it can help you identify the root cause of the issue.

Change Scrolling Behavior

Changing the scrolling behavior in the Performance panel is a great way to customize your experience. You can switch the "Flamechart mouse wheel action" from "Zoom" to "Scroll" in the Settings.

Credit: youtube.com, How to change your navigation style on scroll

By making this change, you'll be able to scroll through the timeline without zooming in. This can be really helpful if you need to quickly scan through a long timeline.

If you want to use both zooming and scrolling, the trick is to hold the Shift key while scrolling. This will toggle between the two behaviors, giving you more control over your navigation.

The Performance panel's default behavior can be a bit confusing at first, but with a little practice, you'll get the hang of it.

Copy Image as Base64 Encoded URI

You can save any image from a webpage out as a data URI or rather base64 encoded. There is no need to use a free online converter as it is already built into Chrome DevTools.

To access this feature, open the Network panel and click on an image.

You can then right click on it to have the option to Copy image as data URI.

This will give you the image in the following format:

Media Queries Debugging

Credit: youtube.com, Chrome DevTools for CSS - Better CSS Coding & CSS Debugging with Developer Tools

Media Queries Debugging is a game-changer for web developers. With dozens of media queries in flight for a given page, it can easily become difficult to keep track of the styles being overwritten by other styles scoped within a media query.

You can find the media query debugger hidden away behind the “Settings” cog in the device toolbar. To access it, toggle the device toolbar with Cmd/Ctrl + Shift + M and choose the three dots in the right upper corner.

The media query debugger shows horizontal bars representing the scope of each media query, which might appear confusing at first but are actually quite helpful. The bars closer to the center of the screen are overwritten by the ones further away from the center.

The blue bar on the top indicates max-width media queries, the green one min-width and max-width media queries, and the orange one stands for only min-width media queries. You can track which media queries each bar contains by hovering over them.

Credit: youtube.com, Master Media Queries And Responsive CSS Web Design Like a Chameleon!

You can jump to a specific media query range and inspect layout issues in detail with the Styles panel open. By clicking on any position on a bar, you can trigger specific breakpoints, and if you right-click on a bar, you can reveal its position in the source code.

With the media query debugger, you can quickly jump back and forth between media queries, rather than resizing the screen manually and checking the screen width over and over again. This saves a ton of time and effort.

Console and Debugging

To open the console in Chrome, click the three-dots icon in the upper-right-hand corner of the browser window and select More tools, then Developer Tools.

You can also use the Chrome dev tools hotkey: F12 on Windows/Linux, or Option + ⌘ + J on macOS.

The console is where you'll identify page errors and warnings, and it's a crucial part of debugging your website.

Opening Console in Different Browsers

Credit: youtube.com, Debugging JavaScript in Chrome DevTools | STOP using console log

Opening the console in your browser is a breeze, and you can do it with just a few clicks. You can also start it using shortcuts or hotkeys.

It only takes a few clicks to open the console in whatever browser you're employing. The process is similar across most popular browsers.

To open the console in your browser, you'll need to follow the instructions for your specific browser. Don't worry, it's easy and straightforward.

The guide below will walk you through the process of opening the console in all the most popular browsers, along with screenshots to help you visualize the steps.

Opening Developer Console

Opening the developer console is a crucial step in console and debugging. You can open it in just a few clicks.

To open the developer console in Chrome, click the three-dots icon in the upper-right-hand corner of the browser window, then click More tools and select Developer Tools from the drop-down list. Alternatively, use the Chrome dev tools hotkey: F12 on Windows/Linux, or Option + ⌘ + J on macOS.

Credit: youtube.com, Enable / Disable JavaScript in Chrome Developer Tools

The console will appear at the bottom or on the right of the Chrome page. You can also use the hotkey to open it quickly.

If you're using a Mac, you can use the following commands to open specific panels: command+option+i to open the last used panel, command+option+j to open the Console panel, and command+option+c to open the Elements panel.

These shortcuts can save you time and make debugging more efficient.

Pretty Print

Pretty Print is a feature in Chrome DevTools that allows you to easily change the formatting of your minimized code. This makes it easier to read and understand your code.

To access Pretty Print, click on the curly braces {} in the DevTools console. This will instantly format your code in a more readable way.

JavaScript Breakpoints

JavaScript breakpoints are a powerful tool for debugging JavaScript code. They allow you to pause the execution of your script at a specific line of code, which can be super helpful when trying to figure out what's going on.

Credit: youtube.com, Debugging JavaScript - Are you doing it wrong?

To set a breakpoint in Chrome DevTools, simply click on the line number you want to break at and then press Cmd + R (Ctrl + R) to refresh the page. This will run the page right to that breakpoint.

You can also use conditional line-of-code breakpoints to pause only when a specific condition is true. This can be really useful when you know the exact region of code you need to investigate.

DOM change breakpoints in DevTools can also be super helpful when testing critical CSS or debugging JavaScript. By right-clicking on the three ominous dots next to an element's name, you can pick "Break on" subtree modifications, attribute modifications, or node removal.

DOMContentLoaded

DOMContentLoaded is a feature that allows you to see the exact DOMContentLoaded time and total load time. This can be beneficial in improving the overall performance of your website or application.

In the Network panel, you can check the Show overview option and then press Cmd + R (Ctrl + R) to refresh the page. A blue line will show up for DOMContentLoaded and a red line for total load time.

Assets that are left of or touching the blue line are blocking the DOM, also referred to as render blocking resources.

Debugging Janky Animations

Credit: youtube.com, How to Debug CSS animations with Google Chrome Inspector

Debugging Janky Animations can be a real challenge, but there are some tools at your disposal to help you track down the issues. The FPS meter from the performance panel in Chrome will reveal if you're running frames smoothly.

A disproportionate amount of memory usage can be a sign of trouble, and tracking which elements are missing a will-change property can help you identify the culprit. If you spot a large component that's hidden off-screen with relative positioning, you might have found your problem.

Safari has a Canvas Memory Usage debugger that can come in handy when debugging canvas issues. This can save you a lot of time and frustration in the long run.

Tracking Changes

Tracking changes can be a real pain, but there's a feature in Chrome that makes it a breeze. Toggle “Local Modifications” command when editing the source file.

You should see a tracker of changes appearing in the panel below. The pane highlights changed properties and what exactly has changed, so you can copy-paste modifications right away.

It's a good idea to track changes while running your local server, as automatic removal of line breaks and spaces can cause issues.

Frequently Asked Questions

How do I use F12 Developer Tools in Chrome?

To access Chrome's F12 Developer Tools, press F12 (Windows/Linux) or Option + ⌘ + J (macOS) to open the console. From there, select the Console option to start examining your code performance.

Cora Stoltenberg

Junior Writer

Cora Stoltenberg is a skilled writer with a passion for crafting engaging content on a wide range of topics. Her expertise spans various categories, including Search Engine Optimization (SEO) Strategies, where she provides actionable tips and insights to help businesses improve their online presence. With a keen eye for detail and a knack for simplifying complex concepts, Cora's writing is both informative and accessible to readers of all levels.

Love What You Read? Stay Updated!

Join our community for insights, tips, and more.