博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Chrome 开发者工具的技巧
阅读量:5050 次
发布时间:2019-06-12

本文共 4946 字,大约阅读时间需要 16 分钟。

Re-posted from .

中文版:


Lately I’ve spent more time than usual using the Chrome Developer Tools. Along the way I found a couple of nice features that I had previously missed (or at least hadn’t needed enough to look for; e.g. blackboxing and asynchronous stacktraces). Because of this, I wanted to summarized a few of the features that I really like about devtools.

  • The little magnifier glass icon that shows you which CSS class/selector in what CSS file that ultimately decides the styling for a specific element and CSS property. For example, select “inspect” on any DOM element and then switch to the “Computed” sub-tab to the right. Find the CSS property you’re interested in and clicking the magnifier icon takes you straight to the correct CSS class/selector in the right .css file (very useful when you start out working on a new large web app):

o_devtools-css-magnifier-icon.png

其实就是自动触发了css浏览器中的filter.
  • To see what XHRs the web app sends while you’re using it, check the “Log XMLHttpRequests” checkbox under “Settings” and keep an eye on the console tab. Before I knew about this, I would set up my browser to go through an HTTP intercept proxy like Burp suite but this more convenient if you just want an quick overview. Of course, with an intercept proxy you also get the opportunity to modify the XHRs before they reach the server, which is really nice for security testing. A lightweight alternative to that is to look under “Sources :: XHR Breakpoints” and activate the “Any XHR” breakpoint.

o_devtools-settings-log-xhr.png

  • Now, suppose that the web app you’re working on is making some XHR at a regular interval (for example, keeping the current view up to date) and you would like to know where this timer is setup (i.e. where the call to setTimeout() or possibly setInterval() is made). To figure this out, you switch to the “Sources” tab, and check the “Async” checkbox. This will make all your stacktraces continue beyond setTimeout() and friends, even multiple levels deep. It does the same thing for requestAnimationFrame() and addEventListener() and a few others too. You’ll find the checkbox here:

o_devtools-async-stacktraces.png

  • To quickly find the code that runs when you click a particular button or link is clicked, activate an “Event listener breakpoint” for Mouse :: Click just before you click the particular button (another killer feature when starting out work on an existing large web app):

o_devtools-event-listener-breakpoints.png

  • When you use “Event listener breakpoint :: Mouse :: Click” you might end up in a third-party library like jQuery at first, and so you’d have to step a few times in the debugger to arrive at the “real” event handler. A great way to avoid this is to “blackbox” the third-party script. The debugger will never stop inside a blackboxed script, instead it continues to run until it reaches a line that isn’t in a blackboxed file. You can blackbox a script by right clicking the filename of the third-party library in the callstack and the selecting “Blackbox Script” from the context menu:

o_devtools-blackbox-third-party-script.png

  • You can jump to a specific file, by name, using ctrl-p (just like in atom):

o_devtools-open-file-ctrl-o.png

太有用了! 之前自己经常需要重复地在Source里面点半天.
  • You can jump to a function, by name (but only in the currently open file), using ctrl-shift-p:

o_devtools-go-to-member.png

  • You can search through all files using ctrl-shift-f:

o_devtools-search-all-files-ctrl-shift-f.png

  • You can edit using multiple simultaneous cursors by selecting some word and then pressing ctrl-d a few times to select more instances of that word (again, just like in atom). Very nice for renaming variables:

o_devtools-multiple-cursors-ctrl-d.gif

好像sublime.
  • When working on a website stored locally it’s possible to edit files in devtools and save the changes directly to disk. To do this, switch to the Sources tab, right click on the Sources sub-tab and select “Add Folder to Workspace” and then finally select the local folder where your project is located. After that, right click the local copy of some file in your site and select “Map to Network Resource…” and then select the corresponding “network” file:

o_devtools-workspace-map-network-resource.png

Other handy tips include:

  • $0 in console is the element you selected in the elements view.
  • You can evaluate XPath expressions using $x("//p") (very useful if you’re writing selenium testcases and CSS selectors doesn’t get you all the way).

I also recommend that you install two Chrome extensions:

  • will indent and syntax highlight JSON blobs for you (and even allow you to expand/collapse blocks). It also makes URLs inside JSON clickable which often makes it possible to explore a JSON-based API via the browser. For example, try navigating to before and after you install it (better formatting) and also (clickable URLs make it easier to explore the API).

  • creates a popup each time a Javascript error is printed to the console. Unfortunately, the main version of this extension submits private “usage data” to a third-party service (see discussion in ). But at any rate, this extension has helped me notice and fix several bugs.

All in all I really like devtools, the only annoying thing that I can think of is that you cannot customize keybindings:

转载于:https://www.cnblogs.com/7z7chn/articles/4986838.html

你可能感兴趣的文章
css修改滚动条样式
查看>>
2018.11.15 Nginx服务器的使用
查看>>
Kinect人机交互开发实践
查看>>
百度编辑器UEditor ASP.NET示例Demo 分类: ASP.NET...
查看>>
JAVA 技术类分享(二)
查看>>
Symfony翻译教程已开课
查看>>
TensorFlow2.0矩阵与向量的加减乘
查看>>
NOIP 2010题解
查看>>
javascript中的each遍历
查看>>
String中各方法多数情况下返回新的String对象
查看>>
浅谈tcp粘包问题
查看>>
UVA11524构造系数数组+高斯消元解异或方程组
查看>>
排序系列之——冒泡排序、插入排序、选择排序
查看>>
爬虫基础
查看>>
jquery.lazyload延迟加载图片第一屏问题
查看>>
OGRE 源码编译方法
查看>>
上周热点回顾(10.20-10.26)
查看>>
前端chrome浏览器调试总结
查看>>
数据库连接
查看>>
delphi.指针.PChar
查看>>