-
Notifications
You must be signed in to change notification settings - Fork 2.6k
fix: resolve webview resource loading errors (ERR_ACCESS_DENIED and 404) #6685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Remove 'strict-dynamic' from CSP to allow dynamically loaded chunks - Update sourcemap plugin to create compatibility files (index.map.json and index.sourcemap) - Fix source map references in build output to use correct file extensions Fixes #6684
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewing my own code is like debugging in a mirror - everything looks backwards but the bugs are still mine.
| <meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"> | ||
| <meta name="theme-color" content="#000000"> | ||
| <meta http-equiv="Content-Security-Policy" content="default-src 'none'; font-src ${webview.cspSource} data:; style-src ${webview.cspSource} 'unsafe-inline'; img-src ${webview.cspSource} https://storage.googleapis.com https://img.clerk.com data:; media-src ${webview.cspSource}; script-src ${webview.cspSource} 'wasm-unsafe-eval' 'nonce-${nonce}' https://us-assets.i.posthog.com 'strict-dynamic'; connect-src ${webview.cspSource} https://openrouter.ai https://api.requesty.ai https://us.i.posthog.com https://us-assets.i.posthog.com;"> | ||
| <meta http-equiv="Content-Security-Policy" content="default-src 'none'; font-src ${webview.cspSource} data:; style-src ${webview.cspSource} 'unsafe-inline'; img-src ${webview.cspSource} https://storage.googleapis.com https://img.clerk.com data:; media-src ${webview.cspSource}; script-src ${webview.cspSource} 'wasm-unsafe-eval' 'nonce-${nonce}' https://us-assets.i.posthog.com; connect-src ${webview.cspSource} https://openrouter.ai https://api.requesty.ai https://us.i.posthog.com https://us-assets.i.posthog.com;"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is removing 'strict-dynamic' from the CSP the only way to fix this? While it solves the immediate issue, it does weaken security slightly. Have you explored alternatives like adding nonces to dynamically imported scripts to maintain the stricter CSP?
| const sourceMappingURLRegex = /\/\/# sourceMappingURL=.*/ | ||
| if (sourceMappingURLRegex.test(jsContent)) { | ||
| // Update existing reference to use correct format | ||
| jsContent = jsContent.replace(sourceMappingURLRegex, `//# sourceMappingURL=${jsFile}.map`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex replacement here could fail silently. Consider adding validation to ensure the replacement was successful:
//# sourceMappingURL=.mapFailed to update source map reference in
| if (fs.existsSync(indexJsPath) && fs.existsSync(indexMapPath)) { | ||
| // Copy index.js.map to index.map.json for compatibility | ||
| const indexMapJsonPath = path.join(assetsDir, "index.map.json") | ||
| fs.copyFileSync(indexMapPath, indexMapJsonPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we reduce duplication here by extracting the compatibility file creation into a helper function? Something like:
Created for compatibility
|
The issue needs to be reproduced, closing for now |
This PR fixes the webview resource loading errors reported in issue #6684 where JavaScript chunks and source maps were failing to load with ERR_ACCESS_DENIED and 404 errors.
Changes:
Testing:
Fixes #6684
Important
Fixes webview resource loading errors by updating CSP and ensuring correct source map references in
ClineProvider.tsandsourcemapPlugin.ts.'strict-dynamic'fromscript-srcin CSP inClineProvider.tsto fix ERR_ACCESS_DENIED for dynamic imports.sourcemapPlugin.tsto ensure all JS files have correctsourceMappingURLreferences and createindex.map.jsonandindex.sourcemapfor compatibility.This description was created by
for 5a44518. You can customize this summary. It will automatically update as commits are pushed.