On Github gaohailang / fe101-devtools
by @siva海浪高
「工欲善其事,必先利其器」
Before digging into Chrome's developer tools,
just a brief look at the development tools
provided by the major browsers.
let's take some time to understand the little controls near the top and bottom.
List the page's markup as it is rendered in the browser.
Show what resources a page uses.
What: The resources panel shows resources associated with the page
Why: Viewing the page's resources is essential for debugging. You might also be curious as to what information other websites store in localStorage, cookies, or any other data storage mechanism. Additionally, certain resources, such as localStorage can be modified via the developer tools.
The button to active the Resources panel. The category pane shows the various types of resources we can inspect. A resource header (such as "Frames" or "Session Storage") may have an error next to it. This indicates there is more information, and clicking on the header reveals that information. This pane is resizable; so make it as large or small as you like. Page resources including fonts, images, JavaScript, CSS and the page itself can be found here. If the page uses multiple frames (for example using a frameset), then each frame appears as a separate folder within the parent "Frames" folder. This is useful for understanding the relationship between a frame and its resources. If Web SQL databases are used in the page, this shows their contents. Similar to Web SQL, IndexedDB displays the contents of the IndexedDB database. Displays the key/value pairs stored in localStorage. Displays the key/value pairs stored in sessionStorage. Lists the cookies created by the domain. Displays the assets cached according to the cache manifest. This section contains a lot of useful information. For example, a resource such as a JavaScript library will show the resource path, file size, and file type. Displays the details regarding the selected resource in the left-hand pane.Each frame is placed inside its own folder
System fonts, such as Arial or Helvetica, are not listed
Info like dimensions, file size, and MIME type are displayed
Content Panel just displays its content, but not much else
More support and capabilities will be added in another panel(Source Panel which we will show right away)When the browser will be unable to load a resource, a red notification appears to the right of the asset
Each resource has a context menu, right-clicking on it
shows a menu similar to this:You can save a resource to your computer, open a resource in a new tab, and perform many other tasks. Double-clicking the resource opens the asset in a new tab.the go-to place for javascript debugging!
The Sources Panel. If you do not see as many scripts as you expect, refresh the page with the Sources panel open. This pane can be either hidden, auto-hidden or fixed. Click on the small icon to the right of 'Content scripts' to toggle between these states. This pane can be resized. The Sources tab within the left-hand side pane; you'll likely have this tab open most of the time. The resources it lists are separated by sub-domain, and you can expect to see CSS, JavaScript and HTML within the tab. The Content Scripts tab (not active in the screenshot) may at first display many oddly named scripts. These are in fact Chrome extensions that loaded on the page. This is useful for debugging actual extensions. Otherwise, you can avoid seeing them by opening your page in an incognito window; most extensions are disabled by default in incognito mode. The main content pane displays the contents of the selected script. Selecting multiple scripts creates a tabbed interface similar to an IDE. This pane contains sub-panels that provide useful JavaScript debugging utilities. At the top of the pane are the icons to step through your code. Watch Expressions does exactly that, it 'watches' expressions you have typed in. If you find yourself wanting to know the value of the this keyword at the various stages of a JavaScript program, you can watch the this keyword to see its different values over time. Click the add button to add an expression, and if an expression doesn't update, hit the small refresh button next to the add button. XHR Breakpoints enables us to halt JavaScript code execution when making an Ajax request. We get even more control over this behavior by supplying a value in the 'Break when URL contains' field, which pops up when you hit the add button. Providing no value causes the debugger to break upon any XHR request. Event Listener breakpoints allow you to set break points for specific events. The screenshot only lists the top level categories. For example, 'Timer' has the following individual event listener breakpoints: 'Set Timer', 'Clear Timer' and 'Timer Fired'. If you encounter minified code, selecting 'Pretty Print' acts as a JavaScript beautifier.You can edit most files in the main content pane, and those changes are immediately reflected in the browser.After you've made a few changes, you can right-click on the resource and select Local Modifications. This opens a new Local Modifications pane which contains a diff of the original and edited files.
Breakpoints lets us halt JavaScript code execution and inspect the current environment. To add a breakpoint, click on the line number; you can also right-click on the line number and choose the "Add Breakpoint" option. breakpoints persist between page loads. refresh, if code is evaluated before.
Note that breaking on a particular event only works when the page in question is listening for that event.useful breakpoint options include: form submission, copying data, DOM mutation events, device orientation, key presses, Ajax requests, mouse events (hovering, moving, clicking etc), setInterval, touchstarts and more.
When inspect large object, you can inspect them by clicking on the drop down arrow immediately to the left of the object.
Console API && Command Shortcuts
发送请求
Make the web jank-free
Investigate your web app's performance issues