16 Ways to Search, Find and Edit with Chrome DevTools

chrome_devtools_find_header

I consistently fumble my way through the searching, finding, and editing UI options in the Chrome Developer Tools (aka Chrome DevTools). The problem is that I haven’t taken the time to learn the fundamentals well enough to remember the basic routines of search-find-edit in-between DevTools uses. I need to remedy this shortcoming.

In this article, I’m going to help myself, and hopefully you the reader, gain a robust understanding of finding things and doing things using Chrome DevTools. Below, you will find 16 short videos detailing solutions to the most common search-find-edit routines using Chrome DevTools.

1. Searching the current HTML

You want to perform a text string search on the current HTML page.

Routine: From the elements panel, use a keyboard shortcut (win: Ctrl+f, mac: Cmd+f) to open up the search input UI. Enter any text you’d like to be found on the current HTML page.

Searching within all sources

You want to perform a text string search across all of the text contained within all of the source files used by the current HTML page.

Routine: From any panel use a keyboard shortcut (win: Ctrl+Shift+f, mac: Cmd+Opt+f) to open up the search panel. Enter any text you’d like to be found within the current HTML page. Note that clicking on one of the results (line number from source) will open the source in the source panel.

3. Searching a source

You want to perform a text string search on an individual source file.

Routine: From the source panel, select and open a source file, then use a keyboard shortcut (win: Ctrl+f, mac: Cmd+f) to open up the search input UI. Enter any text you’d like to be found in the current source file (Note: to un-minify the source click on the {} icon).

4. Searching source file names and paths

You want to perform a text string search across all of the source file names and paths.

Routine: From the source panel, use a keyboard shortcut (win: Ctrl+p, mac: Cmd+p) to bring up the open file UI. Enter any text you’d like to be found in the current source file.

5. Searching console input/output

You want to perform a text string search on the input and output from the console.

Routine: From the console panel, use a keyboard shortcut (win: Ctrl+f, mac: Cmd+f) to open up the search input UI. Enter any text you’d like to be found in the console.

6. Searching file names and URL search values (i.e. ?foo=bar)

You want to perform a text string search on all file names and URL search values sent over the network.

Routine: From the network panel, use a keyboard shortcut (win: Ctrl+f, mac: Cmd+f) to open up the search input UI. Enter any text you’d like to be found in a network path/name.

7. Searching a .css file for specific selector

You want to search a .css source file for a specific CSS selector.

Routine: From the source panel, select and open a .css source file, then use a keyboard shortcut (win: Shift+Ctrl+o, mac: Shift+Cmd+o) to open up a text filterable UI list of CSS selectors contained in the source file (Note: to un-minify the source click on the {} icon).

8. Searching a .js file for specific function

You want to search a .js source file for a specific JavaScript function.

Routine: From the source panel, select and open a .js source file, then use a keyboard shortcut (win: Shift+Ctrl+o, mac: Shift+Cmd+o) to open up a text filterable UI list of JavaScript functions contained within the source file (Note: to un-minify the source click on the {} icon).

9. Finding a DOM node visually

You want to select a DOM node in the elements panel visually using the mouse pointer.

Routine: From the elements panel, click on the magnify icon. Then use the mouse to hover over elements on the page. Click the element you want to view and it will become selected in the elements panel for further investigation.

10. Finding a DOM node using a selector

You want to locate a node element(s) in the DOM using a CSS selector.

Routine 1: From the elements panel, use a keyboard shortcut (win: Ctrl+f, mac: Cmd+f) to open up the search input UI. Enter a CSS selector into the search input UI.

Routine 2: From the console panel, use either the $('selector') or $$('selector') console commands to select element(s) from the DOM. $ uses the querySelector DOM method, which returns a single matching DOM element, while $$ uses querySelectorAll, which returns an array of all matching elements. However, if your site uses jQuery, $ will default to using jQuery rather than querySelector (see the documentation for more details).

11. Edit HTML

You want to make a change to the current HTML page and view the changes on the fly.

Routine 1: From the elements panel, right click on an element node or text node (which will include all child nodes as well) and select, “Edit as HTML”. Make your edits, then click off the selected node for the changes to take effect. (Note: you can also drag and drop DOM nodes in the elements panel to change where the node is in the DOM tree. A node can also be removed by selecting the node hitting the delete key on the keyboard).

12. Edit an element’s attributes

You want to make a change to a specific attribute on an element node in the HTML page and view the changes on the fly.

Routine 1: From the elements panel, right click on a element node and select, “Add Attribute”. If you right click on an actual attribute in the DOM you can select, “Edit Attribute” to edit a specific. Make your edits using the inline input box then hit enter.

13. Edit CSS files

You want to make a change to a .css file and view the changes on the fly.

Routine 1: From the source panel, select and open a .css source file and begin editing. Changes immediately take effect if the CSS is valid.

14. Edit an element’s CSS & Inherited CSS

You want to make a change to the specified or inherited CSS of an element node and view the changes on the fly.

Routine: From the elements panel, select an element node. To the right of the elements panel is a “styles” panel which can be used to add and edit all of the CSS that is applied and inherited by the selected element node.

15. Edit future running JavaScript

You want to make a change to post-page load JavaScript and have the change take effect in the page immediately for future running JavaScript.

Routine: The only JavaScript that you can update on the fly is JavaScript that will continue to run after the initial page load (i.e. a click handler callback function). From the source panel, select and open a .js source file and begin editing any JavaScript that can be invoked after the original page load. Save (win: Ctrl+s, mac: Cmd+s) after you edit.

Conclusion

By learning these 16 routines you will have a robust understanding of the basic use cases for the Chrome Devtools. In fact, these routines might be the most common way in which you engage Devtools, and, knowing them will certainly make you a more efficient developer, if not an all around better front-end developer.

Also, did you know that Telerik offers a Kendo UI inspector plugin for Chrome DevTools? This makes searching, finding, and editing Kendo UI widgets and tools much easier. Check out the video below showcasing its usage.

Build responsive HTML5 apps. Fast.

Comments