Debugging the Webview
The HeapLens webview runs in an isolated iframe within VS Code. It has its own JavaScript context and its own Developer Tools, separate from the Extension Host.
Opening Webview Developer Tools
Method 1: Right-Click (Recommended)
- In the Extension Development Host window, open a
.hproffile - Wait for the HeapLens webview to appear
- Right-click anywhere on the webview content (not the tab bar)
- Select "Inspect Element" or "Open Developer Tools"
Method 2: Command Palette
- Press
Cmd+Shift+P(macOS) orCtrl+Shift+P - Type
Developer: Open Webview Developer Tools - Select the HeapLens webview if prompted
Important Distinction
| Developer Tools | What It Shows | How to Open |
|---|---|---|
| Extension Host Console | TypeScript extension logs, RPC messages | Cmd+Shift+P → "Developer: Toggle Developer Tools" |
| Webview Console | HTML/CSS/JS of the tab UI, D3.js charts | Right-click on webview → Inspect |
The Extension Host console shows console.log from extension.ts, hprofEditorProvider.ts, etc. The Webview console shows console.log from the inline JavaScript in webviewProvider.ts.
What to Look For
Console Tab
Successful initialization looks like:
[Webview] Script loaded
[Webview] VS Code API acquired
[Webview] Waiting for analysis data...
[Webview] Received analysisComplete: 50 top objects, 8421 histogram entries
[Webview] Rendering overview...
[Webview] D3.js pie chart rendered
[Webview] All tabs ready
Common errors:
// D3.js failed to load (CSP or network issue)
Refused to load script from 'https://d3js.org/d3.v7.min.js'
// Data not received
[Webview] Error: Cannot read property 'summary' of undefined
// Chart rendering failure
[Webview] D3 error: invalid arc path
Network Tab
Check that D3.js loads successfully:
- URL:
https://d3js.org/d3.v7.min.js - Status should be 200
- If blocked, check the Content Security Policy in the HTML source
Elements Tab
Useful for:
- Verifying tab content is rendered (look for
<div id="overview-content">,<div id="histogram-content">, etc.) - Checking if tables have rows
- Debugging CSS layout issues
Common Webview Issues
Blank webview (no content at all)
- Check Console for JavaScript errors
- Verify the
nonceattribute matches between the CSP meta tag and the script tags - Check that
npm run compilewas run after changes towebviewProvider.ts
Tabs switch but content is empty
The data may not have been received. Check:
- Console for
[Webview] Received analysisCompletemessage - Extension Host console for RPC errors
- Whether the analysis actually completed (check Output channel)
D3.js charts don't render
- Check Network tab for D3 loading status
- Check Console for D3-specific errors
- Verify the SVG container elements exist in the DOM
Table sorting doesn't work
- Check Console for click handler errors
- Verify the data array is populated (add
console.log(data)temporarily)
Adding Debug Logging
To add temporary debug logging to the webview, edit webviewProvider.ts and add console.log statements in the JavaScript section:
// In the analysisComplete handler
case 'analysisComplete':
console.log('[Webview] Raw data:', JSON.stringify(msg.data).substring(0, 500));
console.log('[Webview] Histogram entries:', msg.data.classHistogram?.length);
console.log('[Webview] Leak suspects:', msg.data.leakSuspects?.length);
break;
Rebuild with npm run compile, restart the Extension Development Host (F5), and check the webview console.
Debugging the Extension Host
For issues in the TypeScript layer (not the webview), use VS Code's built-in debugger:
- Set breakpoints in
src/hprofEditorProvider.tsorsrc/rustClient.ts - Press F5 to launch with debugging
- Trigger the action (open
.hproffile, click a tree node, etc.) - The debugger pauses at breakpoints in the first VS Code window
Logging RPC Messages
To see all JSON-RPC messages between the extension and the Rust server, check the Output channel (View → Output → HeapLens). Progress messages and errors from hprof-server's stderr are displayed there.