1. High-Level Summary (TL;DR)
- Impact: High - Introduces new memory profiling capabilities and enhances the screenshot functionality.
- Key Changes:
- ✨ Added
take-heapsnapshot command to capture V8 heap snapshots via CDP streaming without holding the entire snapshot in memory.
- ✨ Added
inspect-heapsnapshot-node command to parse and inspect specific nodes in a local .heapsnapshot file entirely offline.
- 🖼️ Enhanced the
screenshot command with --quality, --max-width, and --max-height options, and improved page layout metrics gathering.
- 🛠️ Implemented absolute path resolution for CLI arguments (
--output, --file-path) to prevent path mismatch issues between the CLI process and the background daemon.
2. Visual Overview (Code & Logic Map)
graph TD
subgraph "CLI Entry & Routing (src/lib.rs)"
D("run()")
C("build_request()")
C_Abs("absolutize_path()")
end
subgraph "Memory Commands (src/commands/memory.rs)"
E("take_heapsnapshot()")
F("inspect_heapsnapshot_node_offline()")
G("parse_node_from_snapshot()")
end
subgraph "Screenshot Commands (src/commands/screenshot.rs)"
H("take_screenshot()")
end
%% Flow for take-heapsnapshot and screenshot
C -- "Resolves relative paths" --> C_Abs
C_Abs -- "Sends absolute paths" --> E
C_Abs -- "Sends absolute paths" --> H
%% Flow for inspect-heapsnapshot-node
D -- "Intercepts offline command" --> F
F -- "Parses JSON schema" --> G
style D fill:#f3e5f5,color:#7b1fa2
style C fill:#f3e5f5,color:#7b1fa2
style C_Abs fill:#f3e5f5,color:#7b1fa2
style E fill:#c8e6c9,color:#1a5e20
style F fill:#bbdefb,color:#0d47a1
style G fill:#bbdefb,color:#0d47a1
style H fill:#fff3e0,color:#e65100
3. Detailed Change Analysis
Memory Profiling (src/commands/memory.rs & src/lib.rs)
- What Changed:
- Introduced
take_heapsnapshot which enables the HeapProfiler and streams chunks directly to a temporary file via non-blocking CDP events. It atomically renames the temp file upon completion to prevent corrupted files.
- Introduced
inspect_heapsnapshot_node_offline which parses a .heapsnapshot JSON file to find a specific node by ID. This command is intercepted in run() (Source: src/lib.rs) to execute entirely offline, bypassing the need for a Chrome daemon connection.
Screenshot Enhancements (src/commands/screenshot.rs)
- What Changed:
- Refactored
take_screenshot to accept a ScreenshotOptions struct instead of multiple loose parameters.
- Added support for
quality, max_width, and max_height.
- Switched from
Runtime.evaluate to Page.getLayoutMetrics to retrieve page dimensions. This avoids a JavaScript execution round-trip and works natively on non-HTML pages (e.g., PDF viewers, chrome:// pages).
Path Resolution (src/lib.rs)
- What Changed:
- Added
absolutize_path to resolve relative paths (like --output ./file.png) using the CLI's current working directory before sending the request to the daemon. This fixes a bug where the daemon would resolve relative paths against its own startup directory instead of the user's current directory.
New API Commands & Parameters
| Command |
Parameter |
Type |
Required |
Description |
take-heapsnapshot |
--output |
String |
Yes |
Path to save the heap snapshot file |
inspect-heapsnapshot-node |
--file-path |
String |
Yes |
Path to the local .heapsnapshot file |
inspect-heapsnapshot-node |
--node-id |
u64 |
Yes |
ID of the node to inspect |
screenshot |
--quality |
u64 |
No |
Compression quality (0-100), ignores PNG |
screenshot |
--max-width |
f64 |
No |
Downscale screenshot to max width |
screenshot |
--max-height |
f64 |
No |
Downscale screenshot to max height |
4. Impact & Risk Assessment
- Breaking Changes: None. The CLI interface is purely additive. Internal Rust method signatures (like
take_screenshot) have changed, but external usage remains compatible.