Last active
March 27, 2023 21:12
-
-
Save bgrins/7af0c5883c4c31b88a8b45f82aa593af to your computer and use it in GitHub Desktop.
for use in webconsole on https://profiler.firefox.com/
This file contains hidden or 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 zoomOnMarkers(marker1, marker2) { | |
const zeroAt = selectors.profile.getZeroAt(getState()); | |
dispatch(actions.commitRange(marker1.start - zeroAt, marker2.start - zeroAt)); | |
} | |
function resetRange() { | |
dispatch(actions.popCommittedRanges(0)); | |
} | |
function findRanges(suiteName) { | |
const startMarkers = new Map(); | |
const ranges = []; | |
for (const marker of filteredMarkers) { | |
if ( | |
marker.name !== "UserTiming" || | |
!marker.data || | |
!marker.data.name || | |
(suiteName && !marker.data.name.includes(`-${suiteName}`)) | |
) { | |
continue; | |
} | |
const markerName = marker.data.name; | |
if (markerName.startsWith("start-suite-")) { | |
startMarkers.set(markerName.slice("start-suite-".length), marker); | |
} | |
if (markerName.startsWith("end-suite-")) { | |
const baseName = markerName.slice("end-suite-".length); | |
const startMarker = startMarkers.get(baseName); | |
startMarkers.delete(baseName); | |
if (startMarker) { | |
ranges.push([baseName, [startMarker, marker]]); | |
} | |
} | |
} | |
return ranges; | |
} | |
function gatherUrlsForRanges(ranges) { | |
return ranges.map(([baseName, [marker1, marker2]]) => { | |
zoomOnMarkers(marker1, marker2); | |
const location = window.location.href; | |
resetRange(); | |
return [baseName, location]; | |
}); | |
} | |
async function prettyPrint(suiteName) { | |
let results = await run(suiteName); | |
let strs = []; | |
for (const [baseName, url] of results) { | |
strs.push(`${baseName} ${url}`); | |
} | |
console.log("\n" + strs.join("\n")); | |
} | |
// Run with await run() | |
async function run(suiteName) { | |
const dataSource = selectors.urlState.getDataSource(getState()); | |
if (dataSource === "from-browser") { | |
console.error( | |
"This snippet works with an uploaded profile only, but this profile hasn't been yet. Please upload this profile and try again" | |
); | |
} | |
return Promise.all( | |
gatherUrlsForRanges(findRanges(suiteName)).map(async ([baseName, url]) => [ | |
baseName, | |
await shortenUrl(url), | |
]) | |
); | |
} | |
await prettyPrint() |
for reference, here's how we'd change the name dispatch(actions.changeProfileName("New name"))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It would be cool to change the profile title, too, so that the subtest name is shown in the tab label