DevTools
Chrome 開發人員工具  |  Chrome DevTools  |  Chrome for Developers
Firefox DevTools User Docs — Firefox Source Docs documentation
開啟
<C-S-i>/F12/右鍵→Inspect
於DevTools中<C-S-p>可開啟指令面板
可使用如Capture full size screenshot擷取畫面等指令
2024-12-03 DevTools の使い方を可能な限りスクショ付きで解説してみる
Lighthouse
hover至分數上可看到餅狀分佈
FCP
LCP
TBT
CLS
SI
See calculator可看到詳細比重
View Treemap可看到JS檔案的大小比例和執行時的比例
最下方為測量環境的設定
DIAGNOSTICS從上到下為對分數影響大到小的項目
左上角的➕可追加不同的Lighthouse測量
想測量讀取時間的話,可在測量後點開Performance分頁,點擊Record and Reload
其中重點為Network與Main(Thread)
Source分頁→Overrides可改寫請求內容
https://x.com/mizchi/status/1859778640055239096
https://x.com/mizchi/status/1861630290403434914
chrome devtools の tips N 連発 - mizdra
2017-06-13 Chrome Dev Tools 開發者工具實用功能整理
在console中
對視窗中點右鍵,勾選Log XMLHTTPRequest
可以看到該網站所發出的AJAX request
輸入document.designMode = 'on'
點選網頁文字會直接出現游標,可以直接編輯網頁內容
debug
Debugger
Sources→Event Listener Breakpoints
右鍵→Break on...→attribute modifications
Step over Line of Code (step over)
Step into Next Function Call (step into)
Step out of Current Function (step out)
右鍵→clear console history
67 Weird Debugging Tricks Your Browser Doesn't Want You to Know | Alan Norbauer
debugger; fn(1);
頁面跳轉時停止
code:javascript
const dbg = () => {
debugger;
};
history.pushState = dbg;
history.replaceState = dbg;
window.onhashchange = dbg;
window.onpopstate = dbg;
偵測隨機事件
setTimeout(function() { debugger; }, 5000);
偵測focus元素
code:javascript
(function () {
let last = document.activeElement;
setInterval(() => {
if (document.activeElement !== last) {
last = document.activeElement;
console.log("Focus changed to: ", last);
}
})
})();
monitor event
monitorEvents(element, [event])
設定斷點偵測觸發的事件
unmonitorEvents(element, [event])
關閉事件監聽
getEventListeners(element)
查看DOM元素綁定事件
HTML Element
在Chrome DevTools中可以像jQuery使用$當做選擇器
$表示的是document.querySelector([selector])
如果想選擇多個DOM元素,可使用$$
表示的是document.querySelectorAll([selector])
也可以在element視窗中點選一個DOMElement後,在console中輸入$0也可選到該元素
$0表示的是當前chrome所選取到的元素
在console中可以使用keys(obj)和values(obj)來取的物件的鍵和值
可以用document.designMode='on'直接編輯頁面內容
Comprehensive guide to JavaScript performance analysis using Chrome DevTools