Kristyn Hamasaki | 3be83c7eb | 2019-07-16 06:23:21 | [diff] [blame] | 1 | # UI DevTools Overview |
| 2 | |
Wei Li | df2bd70 | 2021-03-10 21:28:22 | [diff] [blame] | 3 | UI DevTools allows UI developers to inspect the Chrome desktop UI system like |
| 4 | a webpage using the frontend DevTools Inspector. It is |
| 5 | currently supported on all desktop platforms including Linux, Windows, Mac, |
| 6 | and ChromeOS. |
Kristyn Hamasaki | 3be83c7eb | 2019-07-16 06:23:21 | [diff] [blame] | 7 | |
| 8 | ## How to run |
| 9 | |
Wei Li | df2bd70 | 2021-03-10 21:28:22 | [diff] [blame] | 10 | There are two ways to enable UI DevTools: |
Kristyn Hamasaki | 3be83c7eb | 2019-07-16 06:23:21 | [diff] [blame] | 11 | |
Wei Li | df2bd70 | 2021-03-10 21:28:22 | [diff] [blame] | 12 | 1. Run Chromium with default port 9223 and start Chromium with UI DevTools |
| 13 | command line flag: |
Kristyn Hamasaki | 3be83c7eb | 2019-07-16 06:23:21 | [diff] [blame] | 14 | |
Wei Li | df2bd70 | 2021-03-10 21:28:22 | [diff] [blame] | 15 | ```shell |
| 16 | $ out/Default/chrome --enable-ui-devtools |
| 17 | ``` |
| 18 | |
| 19 | * If you want to use a different port, add the port number in the flag |
| 20 | `--enable-ui-devtools=<port>`. |
| 21 | |
| 22 | 2. Enable `ui-debug-tools` feature flag from `chrome://flags` |
| 23 | |
| 24 | Once enabled, go to `chrome://inspect#native-ui` and click the `Inspect Native UI` |
| 25 | button to launch the DevTools front-end in a separate tab. |
| 26 | |
| 27 | ![launch UIDevTools] |
Kristyn Hamasaki | 3be83c7eb | 2019-07-16 06:23:21 | [diff] [blame] | 28 | |
| 29 | |
Kristyn Hamasaki | 0f6e425 | 2019-08-16 22:13:11 | [diff] [blame] | 30 | ## How to Use |
Kristyn Hamasaki | 3be83c7eb | 2019-07-16 06:23:21 | [diff] [blame] | 31 | |
Kristyn Hamasaki | 0f6e425 | 2019-08-16 22:13:11 | [diff] [blame] | 32 | ### Elements Tree |
| 33 | |
| 34 | View, Window, and Widget elements are displayed in the hierarchal elements tree. To expand the elements |
| 35 | tree, right click the root element and then select Expand Recursively from the context menu. |
| 36 | Then, to inspect an element's properties, click on its elements node. |
| 37 | |
| 38 | ![expand elements] |
| 39 | |
| 40 | ### Views Property Inspection |
| 41 | |
| 42 | When an element in the elements tree is selected, the property panel on the right side displays the |
| 43 | element's properties. All elements have the basic properties (height, width, x, y, visibility). |
| 44 | For Window and View elements, if that element has Layer properties, they will be displayed in |
| 45 | a separate section. |
| 46 | |
| 47 | ![browser frame properties] |
| 48 | |
| 49 | For View elements with Metadata properties, each parent class's properties from the Metadata |
| 50 | will be displayed in an additional section. |
| 51 | |
| 52 | ![image view properties] |
| 53 | |
| 54 | Elements' basic properties can be modified from the properties panel and changes will be shown. |
| 55 | |
| 56 | ![edit property] |
| 57 | |
| 58 | ### Inspect Mode |
| 59 | |
| 60 | To enter inspect mode, click the inspect icon at top left corner of UI Devtools. |
| 61 | |
| 62 | ![inspector button] |
| 63 | |
| 64 | Hovering over a UI element highlights that element with a blue rectangular border and reveals |
| 65 | the element's node in the elements tree. |
| 66 | |
| 67 | ![hovering over elements] |
| 68 | |
| 69 | Clicking on a highlighted element will pin that element. Clicking the corresponding node |
| 70 | in the elements tree will reveal that element's properties. |
| 71 | |
| 72 | ![hover and inspect] |
| 73 | |
| 74 | When an element is pinned, hovering over other elements will reveal the vertical and horizontal |
| 75 | distance between the two elements. |
| 76 | |
| 77 | ![hovering distances] |
| 78 | |
| 79 | To exit inspect mode, either click the inspect icon again or press the Esc key. |
| 80 | |
| 81 | ### Sources Panel |
| 82 | |
| 83 | In the properties panel, each section has a source link in the upper right corner. When right-clicked, |
| 84 | the context menu shows the option to "Open in new tab," which opens the class's header file in Chromium |
| 85 | code search. |
| 86 | |
| 87 | ![properties panel right click link] |
| 88 | |
| 89 | If the link is simply clicked, it will open the source code in the sources panel of UI DevTools, which |
| 90 | is read in from local files. |
| 91 | |
| 92 | ![sources panel] |
| 93 | |
| 94 | ### View Bounds Highlighting |
| 95 | |
| 96 | Red border rectangles around each View element can be drawn using the command Ctrl+R (Meta+R for mac). |
| 97 | The rectangles can be toggled off and on using the same command. |
| 98 | |
| 99 | ![debug bounds rectangles] |
| 100 | |
| 101 | ### Bubble Locking |
| 102 | |
| 103 | In order to inspect a bubble, the command Ctrl+Shift+R (Meta+Shift+R for mac) locks bubbles to prevent |
| 104 | them from dismissing upon losing focus. This allows a bubble's inner elements to be inspected. Bubble |
| 105 | locking can be toggled off and on using the same command. |
| 106 | |
| 107 | ![lock and inspect bubble] |
| 108 | |
Andrew Lee | 11cbca6 | 2019-08-21 16:39:08 | [diff] [blame] | 109 | ### UI Element Tree Search |
| 110 | |
| 111 | In the elements panel, Ctrl+F to open the search bar at the bottom. The search functionality allows |
| 112 | developers to search the UI element tree quickly by name, tag <>, and style properties. |
| 113 | The search can do substring matches or exact matches (specified with quotations). The search returns |
| 114 | all matches and highlights the specific nodes on the tree that are matched. The up and down arrows |
| 115 | on the right of the search bar or ENTER are used to traverse through the matches. |
| 116 | |
| 117 | ![ui element tree search] |
| 118 | |
| 119 | The search feature can also search the element's style properties in the UI element tree. The special |
| 120 | key word 'style:' must be typed in the search bar. |
| 121 | |
| 122 | ![search style] |
| 123 | |
Wei Li | df2bd70 | 2021-03-10 21:28:22 | [diff] [blame] | 124 | [launch UIDevTools]: images/launch_tools.png |
Kristyn Hamasaki | 0f6e425 | 2019-08-16 22:13:11 | [diff] [blame] | 125 | [expand elements]: images/expand_elements.gif |
| 126 | [browser frame properties]: images/browser_frame_properties.png |
| 127 | [image view properties]: images/image_view_properties.png |
| 128 | [edit property]: images/edit_property.gif |
| 129 | [inspector button]: images/inspector_button.png |
| 130 | [hovering over elements]: images/hovering_over_elements.gif |
| 131 | [hover and inspect]: images/hover_and_inspect.gif |
| 132 | [hovering distances]: images/hovering_distances.gif |
| 133 | [properties panel right click link]: images/properties_panel_right_click_link.png |
| 134 | [sources panel]: images/sources_panel.png |
| 135 | [debug bounds rectangles]: images/debug_bounds_rectangles.png |
| 136 | [lock and inspect bubble]: images/lock_and_inspect_bubble.gif |
Andrew Lee | 11cbca6 | 2019-08-21 16:39:08 | [diff] [blame] | 137 | [ui element tree search]: images/ui_element_tree_search.gif |
| 138 | [search style]: images/search_style.png |
Wei Li | df2bd70 | 2021-03-10 21:28:22 | [diff] [blame] | 139 | |
| 140 | ### References |
| 141 | |
| 142 | * [Old Ash Doc](https://www.chromium.org/developers/how-tos/inspecting-ash) (obsolete) |
| 143 | * [Backend Source Code](https://cs.chromium.org/chromium/src/components/ui_devtools/) |
| 144 | * [Inspector Frontend Source Code](https://chromium.googlesource.com/devtools/devtools-frontend) |