Skip to content

Add screenshot list and screenshot save commands to profiler-cli - #6523

Open
canova wants to merge 4 commits into
canova/reject-inverted-rangesfrom
canova/screenshots-cli
Open

canova wants to merge 4 commits into
canova/reject-inverted-rangesfrom
canova/screenshots-cli

Conversation

@canova

@canova canova commented Dec 4, 2026

Copy link
Copy Markdown
Member

Stacked on #6522. (again trying stacked PRs, let's see if they are gonna work)

This PR adds two commands:

  • screenshot list lists the screenshot frames of the current view with their marker handles, grouped by window.
  • screenshot save -o <dir> writes frames as image files named <time>-<m-N>.<ext>, so they sort by time. Frames are picked by marker handle, --range (the frames on screen during a range, e.g. --range m-500 for a jank marker), --at (the frame of each window on screen at a time) or --all.
"CompositorScreenshot 42" on t-0 (Parent Process): 2 frames, 1280×1000, 0.006s - 0.014s
  m-1       t=0.006s        6ms
  m-2       t=0.012s        2ms

The screenshot track found a marker's image through its schema, and the
screenshot under the mouse, inside the component. Move both into
profile-logic, and group the screenshot marker indexes by name in their
own selector, so that profiler-cli can use the same logic.
Inline source maps were decoded by a private helper in embed-js-sources.
Move it next to the other data URL helpers and return the media type and
bytes, so that binary data URLs like screenshots can use it too.
"screenshot list" lists the screenshot frames of the current view with
their m-N handles, grouped by window. "screenshot save" writes frames as
image files into a directory, named "<time>-<m-N>.<ext>", so that they
can be looked at: given marker handles, the frames on screen during a
--range, the frame of each window on screen --at a time, or every frame
of the view with --all.

--range and --at take the "zoom push" syntax and apply inside the
current zoom. --search keeps the windows whose marker name matches.
…info

"profile info" lists the screenshot windows with frames in the current
view, so that they can be found without knowing about "screenshot list".
"marker info" on a screenshot frame says how to save it as an image.
@canova
canova added this pull request to stack #6524 December 4, 2026 14:16
@canova
canova requested review from fatadel and a balanced review from Copilot December 4, 2026 14:19

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Screenshot handling still rejects valid percent-encoded images, includes unsavable and out-of-view frames, and produces incorrect chronological filename ordering for submillisecond timestamps.

4 open issues
What changed in this PR

Adds screenshot discovery and image export to profiler-cli, reusing shared screenshot logic and the range syntax introduced in #6522.

Changes:

  • Lists frames by window and saves images selected by handle, range, time, or --all.
  • Adds screenshot summaries, command routing, output formatting, and documentation.
  • Shares screenshot helpers with the timeline UI and adds unit and integration coverage.
File Description
src/​utils/​base64.ts Adds synchronous data URL decoding.
src/​test/​unit/​profile-query/​screenshots.test.ts Tests screenshot queries and exports.
src/​test/​unit/​base64.test.ts Tests data URL decoding.
src/​selectors/​per-thread/​markers.ts Groups screenshot indexes by name.
src/​profile-query/​types.ts Defines screenshot query types.
src/​profile-query/​screenshots.ts Implements frame selection and export.
src/​profile-query/​index.ts Exposes screenshot queries.
src/​profile-query/​formatters/​profile-info.ts Adds screenshot summaries.
src/​profile-query/​formatters/​marker-info.ts Identifies screenshot markers.
src/​profile-logic/​marker-schema.ts Extracts shared image metadata logic.
src/​profile-logic/​marker-data.ts Adds shared time-based frame lookup.
src/​profile-logic/​embed-js-sources.ts Reuses data URL decoding.
src/​components/​timeline/​TrackScreenshots.tsx Uses shared screenshot helpers.
profiler-cli/​src/​test/​unit/​network-formatting.test.ts Updates profile-info fixtures.
profiler-cli/​src/​test/​unit/​marker-formatting.test.ts Updates marker-info fixtures.
profiler-cli/​src/​test/​integration/​screenshot.test.ts Tests end-to-end screenshot commands.
profiler-cli/​src/​protocol.ts Adds screenshot commands and results.
profiler-cli/​src/​permalink-view.ts Handles screenshot permalink routing.
profiler-cli/​src/​output.ts Routes screenshot output formatting.
profiler-cli/​src/​index.ts Registers commands and examples.
profiler-cli/​src/​formatters.ts Formats screenshot results and hints.
profiler-cli/​src/​daemon.ts Dispatches screenshot requests.
profiler-cli/​src/​commands/​screenshot.ts Defines command options and actions.
profiler-cli/​schemas.txt Documents screenshot JSON results.
profiler-cli/​README.md Lists screenshot commands.
profiler-cli/​guide.txt Adds screenshot workflow examples.

Review effort: Balanced

tracks.push({
threadIndexes,
window: makeScreenshotWindow(state, threadMap, threadIndexes, markerName),
markerIndexes: indexesByName.get(markerName) ?? [],
Comment on lines +99 to +108
const indexesByName =
getThreadSelectors(threadIndex).getRangeFilteredScreenshotIndexesByName(
state
);
const threadIndexes = new Set([threadIndex]);
tracks.push({
threadIndexes,
window: makeScreenshotWindow(state, threadMap, threadIndexes, markerName),
markerIndexes: indexesByName.get(markerName) ?? [],
});
Comment on lines +344 to +345
const formatFileTime = (relativeMs: number) =>
`${(relativeMs / 1000).toFixed(3).padStart(secondsWidth + 4, '0')}s`;
Comment thread src/utils/base64.ts
Comment on lines +43 to +49
return {
// RFC 2397 makes a missing media type mean text/plain.
mediaType: header.split(';')[0] || 'text/plain',
bytes: header.endsWith(';base64')
? new Uint8Array(base64StringToBytes(data))
: new TextEncoder().encode(decodeURIComponent(data)),
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants