#9997 Paths are not properly mapped for debugging
Investigate where file:// scheme is stripped; add URL normalization in inspector proxy
N/A
Analysis Report
Issue Review: cloudflare/workers-sdk#9997
Summary
Debugging breakpoints fail for files with special characters (brackets) in their paths because the source.path in DAP messages is sent without the file:// scheme prefix.
Findings
- Created: 2025-07-17
- Updated: 2025-07-17
- Version: v4.24 -> v4.60.0
- Component: wrangler (debugging/inspector proxy)
- Labels: bug
- Comments: 0
Key Evidence
- No PRs reference or fix this issue (#9997)
- No changelog entry mentions this issue
- Issue describes clear reproduction steps with files named
[foo].ts - Problem:
source.pathis/path/to/%5Bfoo%5D.tsinstead offile:///path/to/%5Bfoo%5D.ts - The
source-url.tsfile correctly usespathToFileURL()which produces properfile://URLs - The
handleRuntimeScriptParsedfunction in inspector proxies handlessourceMapURLbut not the main scripturlin the DAPDebugger.scriptParsedevent - Related code exists in multiple places:
InspectorProxyWorker.ts,inspector-proxy.ts, andsource-url.ts
Root Cause Analysis
The issue appears to be in how URLs with special characters (like brackets []) are handled by VSCode's JS debug adapter when the path doesn't have a proper file:// scheme.
Source URL Generation (
packages/wrangler/src/deployment-bundle/source-url.ts:4-6):function withSourceURL(source: string, sourcePath: string) { return `${source}\n//# sourceURL=${pathToFileURL(sourcePath)}`; }This correctly produces
file:///path/to/[foo].tsURLs.URL Handling in Inspector Proxy (
packages/wrangler/templates/startDevWorker/InspectorProxyWorker.ts:243-264):
ThehandleRuntimeScriptParsedfunction only processessourceMapURLand not the mainurlparameter. When VSCode's debug adapter receives paths with URL-encoded characters (like%5Bfor[), it may not properly resolve them without thefile://scheme.Possible Cause: The issue might be in workerd/V8's inspector output, or in how the URL is decoded/re-encoded in the proxy layer. The URL-encoded characters (
%5B,%5D) in the path need thefile://scheme for VSCode to correctly interpret them.
Proposed Solution
The fix should ensure that when Debugger.scriptParsed events pass through the inspector proxy, paths with special characters are properly formatted with the file:// scheme.
Option A: Validate and fix URL in handleRuntimeScriptParsed
In packages/wrangler/templates/startDevWorker/InspectorProxyWorker.ts:
handleRuntimeScriptParsed(msg: DevToolsEvent<"Debugger.scriptParsed">) {
// Ensure the main script URL has a proper file:// scheme
// This is necessary for paths with special characters (brackets, etc.)
if (msg.params.url && !msg.params.url.includes(':')) {
// URL appears to be a bare path, convert to file:// URL
try {
const fileUrl = new URL('file://' + encodeURI(msg.params.url));
msg.params.url = fileUrl.href;
} catch {
// If conversion fails, leave as-is
}
}
// ... existing sourceMapURL handling
}
Option B: Fix at source-url.ts level
Ensure all paths passed to the inspector are consistent file:// URLs and investigate if workerd strips the scheme somewhere.
Recommendation
Status: KEEP OPEN
Reasoning: This is a valid bug with clear reproduction steps. No fix has been merged, and debugging is a critical developer experience feature. The issue affects any file with special characters in its name (brackets, spaces, etc.).
Action:
- Investigate where the
file://scheme is being stripped or not added - Check if workerd/V8 sends bare paths in
Debugger.scriptParsedevents - Add URL normalization in the inspector proxy to ensure proper
file://scheme
Implementation Details
Files to Modify:
packages/wrangler/templates/startDevWorker/InspectorProxyWorker.ts- Add URL normalization inhandleRuntimeScriptParsedpackages/miniflare/src/plugins/core/inspector-proxy/inspector-proxy.ts- Mirror fix for miniflare's inspector proxypackages/wrangler/src/deployment-bundle/source-url.ts- VerifypathToFileURLis being used consistently
Implementation Difficulty: Medium
- The fix itself is relatively simple (URL normalization)
- However, it requires:
- Understanding the exact point where the scheme is lost
- Testing across multiple debug scenarios (VSCode, WebStorm, Chrome DevTools)
- Ensuring the fix doesn't break existing debugging workflows
- Handling edge cases (already valid URLs, relative paths, etc.)
Testing Recommendations:
- Create a test worker with a file named
[foo].tscontaining a simple function - Set a breakpoint in VSCode and verify it binds correctly
- Test stepping into the function from another file
- Test with other special characters: spaces, parentheses, unicode
- Verify Chrome DevTools still works correctly
- Add unit tests for URL normalization in inspector proxy tests
Notes & Feedback (0)
No notes yet.