Skip to content

Chrome Dev Tools

  • 各个面板的功能介绍
  • Css debug 和 js debug
  • 一些小技巧
  • ...

1 各个Tab介绍

1.1 打开Dev Tool

  • 菜单>更多工具>开发者工具
  • 快捷键:F12

Screenshot 2025-04-05 at 17.23.59

1.2 打开命令菜单

  • 快捷键:
  • CTRL + SHIFT + P
  • Command + SHIFT + P(MAC)

Screenshot 2025-04-05 at 17.25.33

  • DevTool的黑色主题

Screenshot 2025-04-05 at 17.51.49

Screenshot 2025-04-05 at 17.52.02

Screenshot 2025-04-05 at 17.26.29

  • screenshot

Screenshot 2025-04-05 at 17.52.55

full shot

Screenshot 2025-04-05 at 17.53.44

screenshot node

Screenshot 2025-04-05 at 17.54.47

Screenshot 2025-04-05 at 18.11.36

  • dock

Screenshot 2025-04-05 at 18.12.20

1.2 常用的Tab

  • Element
  • Console
  • Source
  • Network
  • Vue/React

Screenshot 2025-04-05 at 18.13.12

2 Css 调试

2.1 检查元素

  • “检查我”

Screenshot 2025-04-05 at 18.40.12

Screenshot 2025-04-05 at 19.01.24

2.2 查询DOM树

  • 快捷键:

  • CTRL+F

  • Command+F(MAC)

  • 查询方式:

  • 文本查询

    Screenshot 2025-04-05 at 19.04.09

  • css选择器

    Screenshot 2025-04-05 at 19.04.46

  • Xpath

    Screenshot 2025-04-05 at 19.11.26

2.3 Console

  • inspect(element)

Screenshot 2025-04-05 at 19.31.50

Screenshot 2025-04-05 at 19.32.24

3 编辑样式

  • 用auto-complete特性给元素添加样式

Screenshot 2025-04-05 at 19.37.32

Screenshot 2025-04-05 at 20.00.42

  • 让:hover常驻悬停!

Screenshot 2025-04-05 at 20.28.14

  • 编辑class

  • 别动我

  • 改我改我~

  • 别动我

    Screenshot 2025-04-05 at 20.40.39

  • 复制样式

Screenshot 2025-04-05 at 21.05.12

Screenshot 2025-04-06 at 12.16.11

Computed的面板是不按照class区分的, 只是把所有样式列出来了.

Screenshot 2025-04-06 at 12.30.45

可以快速定位

Screenshot 2025-04-06 at 12.41.29

group功能上的区分.

Screenshot 2025-04-06 at 12.44.32

Layout是前端页面经常用到的布局, 一个是Grid布局(网格布局), 另一个是Flexbox(弹性布局). 这个布局, 把我们所有用到grid布局, flexbox布局的容器全部列在这里了.

Screenshot 2025-04-06 at 12.49.21

Screenshot 2025-04-06 at 12.50.04

  • DevTool的黑色主题

  • 截屏

4 控制台(Console)

  • 快捷键

  • Ctrl+Shift+J

  • Command+Option+J(MAC)

  • 执行语句

  • $_ 上一条语句

Screenshot 2025-04-06 at 13.26.40

  • $0 上一个选择的DOM节点($1, $2...)

Screenshot 2025-04-06 at 13.27.34

Screenshot 2025-04-06 at 13.28.39

  • console.log (error warn table clear group time assert trace)

  • Log级别筛选

Screenshot 2025-04-06 at 13.33.07

Screenshot 2025-04-06 at 13.34.10

Screenshot 2025-04-06 at 13.35.25

Screenshot 2025-04-06 at 13.35.56

Screenshot 2025-04-06 at 13.36.53

Screenshot 2025-04-06 at 13.37.03

5 Javascript 调试

        window.addEventListener('load', () => {
            document.getElementById("change-color-btn").addEventListener("click", function () {
                function rgb() {
                    const value = () => Math.floor(Math.random() * 255);

                    //debugger;
                    const irrelevantFunction = () => {
                        let someStr = '';
                        for (let i = 0; i < 10; i++) {
                            someStr += i;
                        }
                        return someStr;
                    }

                    irrelevantFunction();

                    const r = value();
                    const g = value();
                    const b = value();

                    return { r, g, b };
                }

                const color = rgb();

                this.style.color = `rgb(${color.r}, ${color.g}, ${color.b})`;
            });
        })

Screenshot 2025-04-06 at 13.50.15

Screenshot 2025-04-06 at 13.50.47

Screenshot 2025-04-06 at 14.02.06

Screenshot 2025-04-06 at 14.04.04

Screenshot 2025-04-06 at 14.07.03

Screenshot 2025-04-06 at 14.07.42

Screenshot 2025-04-06 at 14.09.36

Screenshot 2025-04-06 at 14.11.41

subtree modifications: 以这个为根节点, 它里面的一些子节点被修改的话, 那么js的运行就会暂停

attribute modifications: 一些属性被修改了, 也会暂停

node removal: 从文档里这个节点被删除的话, 代码执行也会被暂停.

Screenshot 2025-04-06 at 14.21.16

去掉debugger

Screenshot 2025-04-06 at 14.21.54

Screenshot 2025-04-06 at 14.25.31

Screenshot 2025-04-06 at 14.26.37

不需要调试vue.js

Screenshot 2025-04-06 at 14.27.14

Screenshot 2025-04-06 at 14.27.34

Screenshot 2025-04-06 at 14.27.50

6 Network

发送请求

Screenshot 2025-04-06 at 14.28.30

Screenshot 2025-04-06 at 14.29.32

点击变灰, 不再监听网络发起的请求, 点击不会有反应.

Screenshot 2025-04-06 at 14.30.38

第二个是clear, 清空

Preserve log: 历史的也保留

Screenshot 2025-04-06 at 17.32.49

Throttling: 截流器, 模拟用户网络状态

Screenshot 2025-04-06 at 17.33.20

Screenshot 2025-04-06 at 17.47.24

Screenshot 2025-04-06 at 17.49.28

Reference

https://www.bilibili.com/video/BV1KM4y1G7EF/?spm_id_from=333.337.search-card.all.click&vd_source=73e7d2c4251a7c9000b22d21b70f5635