Skip to content

Commit 5a44518

Browse files
committed
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
1 parent 7ca4901 commit 5a44518

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ export class ClineProvider
920920
<meta charset="utf-8">
921921
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
922922
<meta name="theme-color" content="#000000">
923-
<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;">
923+
<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;">
924924
<link rel="stylesheet" type="text/css" href="${stylesUri}">
925925
<link href="${codiconsUri}" rel="stylesheet" />
926926
<script nonce="${nonce}">

webview-ui/src/vite-plugins/sourcemapPlugin.ts

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,17 @@ export function sourcemapPlugin(): Plugin {
6161
let jsContent = fs.readFileSync(jsPath, "utf8")
6262

6363
// Check if the source map is already referenced
64-
if (!jsContent.includes("//# sourceMappingURL=")) {
64+
// Check for existing source map reference and update it if needed
65+
const sourceMappingURLRegex = /\/\/# sourceMappingURL=.*/
66+
if (sourceMappingURLRegex.test(jsContent)) {
67+
// Update existing reference to use correct format
68+
jsContent = jsContent.replace(sourceMappingURLRegex, `//# sourceMappingURL=${jsFile}.map`)
69+
fs.writeFileSync(jsPath, jsContent)
70+
console.log(`Updated source map reference in ${jsFile}`)
71+
} else {
72+
// Add source map reference if missing
6573
console.log(`Adding source map reference to ${jsFile}`)
66-
67-
// Add source map reference
6874
jsContent += `\n//# sourceMappingURL=${jsFile}.map\n`
69-
70-
// Write the updated JS file
7175
fs.writeFileSync(jsPath, jsContent)
7276
}
7377

@@ -99,6 +103,22 @@ export function sourcemapPlugin(): Plugin {
99103
}
100104
}
101105

106+
// Create index.map.json and index.sourcemap files for compatibility
107+
const indexJsPath = path.join(assetsDir, "index.js")
108+
const indexMapPath = path.join(assetsDir, "index.js.map")
109+
110+
if (fs.existsSync(indexJsPath) && fs.existsSync(indexMapPath)) {
111+
// Copy index.js.map to index.map.json for compatibility
112+
const indexMapJsonPath = path.join(assetsDir, "index.map.json")
113+
fs.copyFileSync(indexMapPath, indexMapJsonPath)
114+
console.log("Created index.map.json for compatibility")
115+
116+
// Also create index.sourcemap
117+
const indexSourcemapPath = path.join(assetsDir, "index.sourcemap")
118+
fs.copyFileSync(indexMapPath, indexSourcemapPath)
119+
console.log("Created index.sourcemap for compatibility")
120+
}
121+
102122
// Create a special file to enable source map loading in production
103123
fs.writeFileSync(
104124
path.join(outDir, "sourcemap-manifest.json"),

0 commit comments

Comments
 (0)