Last active
May 13, 2022 07:23
-
-
Save victorporof/a82efafc203179966a712e6f8155bf4b to your computer and use it in GitHub Desktop.
Perf Extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="devtools.js"></script> | |
</head> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chrome.devtools.panels.create("My Panel", null, "panel.html", function (panel) { | |
// | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"action": {}, | |
"devtools_page": "devtools.html", | |
"key": "...", | |
"manifest_version": 3, | |
"name": "DevTools Perf!", | |
"permissions": ["debugger"], | |
"version": "1.0" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<style> | |
:root[recording] .record-button { | |
color: red; | |
} | |
</style> | |
</head> | |
<body> | |
<input class="record-button" type="button" /> | |
<script src="utils.js"></script> | |
<script src="panel.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const state = { | |
isRecording: false, | |
}; | |
const recordButton = document.querySelector(".record-button"); | |
recordButton.addEventListener("click", toggleRecording); | |
function render() { | |
if (state.isRecording) { | |
document.documentElement.setAttribute("recording", "true"); | |
recordButton.setAttribute("value", "Stop Recording"); | |
} else { | |
document.documentElement.removeAttribute("recording"); | |
recordButton.setAttribute("value", "Start Recording"); | |
} | |
} | |
async function toggleRecording() { | |
if (!state.isRecording) { | |
startRecording(); | |
} else { | |
stopRecording(); | |
} | |
} | |
async function startRecording() { | |
await sendCommand(getInspectedTab(), "DOM.disable"); | |
await sendCommand(getInspectedTab(), "CSS.disable"); | |
await sendCommand(getInspectedTab(), "Overlay.disable"); | |
await sendCommand(getInspectedTab(), "Tracing.start", makeTracingParams()); | |
state.isRecording = true; | |
render(); | |
} | |
async function stopRecording() { | |
await sendCommand(getInspectedTab(), "DOM.enable"); | |
await sendCommand(getInspectedTab(), "CSS.enable"); | |
await sendCommand(getInspectedTab(), "Overlay.enable"); | |
await sendCommand(getInspectedTab(), "Tracing.end", makeTracingParams()); | |
state.isRecording = false; | |
render(); | |
} | |
attach(getInspectedTab(), "1.0").then(render); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function promisify(f) { | |
return (...args) => new Promise((resolve) => f(...args, resolve)); | |
} | |
const attach = promisify(chrome.debugger.attach); | |
const sendCommand = promisify(chrome.debugger.sendCommand); | |
function getInspectedTab() { | |
return { tabId: chrome.devtools.inspectedWindow.tabId }; | |
} | |
function makeTracingParams() { | |
return { | |
bufferUsageReportingInterval: 500, | |
categories: [ | |
"-*", | |
"devtools.timeline", | |
"disabled-by-default-devtools.timeline", | |
"disabled-by-default-devtools.timeline.frame", | |
"v8.execute", | |
"disabled-by-default-v8.compile", | |
"blink.console", | |
"blink.user_timing", | |
"loading", | |
"latencyInfo", | |
"disabled-by-default-v8.cpu_profiler", | |
"disabled-by-default-devtools.timeline.stack", | |
"disabled-by-default-devtools.screenshot", | |
].join(","), | |
options: "", | |
transferMode: "ReportEvents", | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i tweaked the extension to show the trace data collected.