fix: resolve webview resource loading errors (ERR_ACCESS_DENIED and 404)

- 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
This commit is contained in:
Roo Code 2025-08-04 20:08:29 +00:00
parent 7ca4901024
commit 5a44518cdb
2 changed files with 26 additions and 6 deletions

View file

@ -920,7 +920,7 @@ export class ClineProvider
<meta charset="utf-8">
<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;">
<link rel="stylesheet" type="text/css" href="${stylesUri}">
<link href="${codiconsUri}" rel="stylesheet" />
<script nonce="${nonce}">

View file

@ -61,13 +61,17 @@ export function sourcemapPlugin(): Plugin {
let jsContent = fs.readFileSync(jsPath, "utf8")
// Check if the source map is already referenced
if (!jsContent.includes("//# sourceMappingURL=")) {
// Check for existing source map reference and update it if needed
const sourceMappingURLRegex = /\/\/# sourceMappingURL=.*/
if (sourceMappingURLRegex.test(jsContent)) {
// Update existing reference to use correct format
jsContent = jsContent.replace(sourceMappingURLRegex, `//# sourceMappingURL=${jsFile}.map`)
fs.writeFileSync(jsPath, jsContent)
console.log(`Updated source map reference in ${jsFile}`)
} else {
// Add source map reference if missing
console.log(`Adding source map reference to ${jsFile}`)
// Add source map reference
jsContent += `\n//# sourceMappingURL=${jsFile}.map\n`
// Write the updated JS file
fs.writeFileSync(jsPath, jsContent)
}
@ -99,6 +103,22 @@ export function sourcemapPlugin(): Plugin {
}
}
// Create index.map.json and index.sourcemap files for compatibility
const indexJsPath = path.join(assetsDir, "index.js")
const indexMapPath = path.join(assetsDir, "index.js.map")
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)
console.log("Created index.map.json for compatibility")
// Also create index.sourcemap
const indexSourcemapPath = path.join(assetsDir, "index.sourcemap")
fs.copyFileSync(indexMapPath, indexSourcemapPath)
console.log("Created index.sourcemap for compatibility")
}
// Create a special file to enable source map loading in production
fs.writeFileSync(
path.join(outDir, "sourcemap-manifest.json"),