Skip to content

Commit b549d42

Browse files
committed
fix getAudioUrl and CSP
1 parent 31d1d2d commit b549d42

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
595595
])
596596

597597
const imagesUri = getUri(webview, this.contextProxy.extensionUri, ["assets", "images"])
598+
const audioUri = getUri(webview, this.contextProxy.extensionUri, ["webview-ui", "audio"])
598599

599600
const file = "src/index.tsx"
600601
const scriptUri = `http://${localServerUrl}/${file}`
@@ -614,6 +615,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
614615
`font-src ${webview.cspSource}`,
615616
`style-src ${webview.cspSource} 'unsafe-inline' https://* http://${localServerUrl} http://0.0.0.0:${localPort}`,
616617
`img-src ${webview.cspSource} data:`,
618+
`media-src ${webview.cspSource}`,
617619
`script-src 'unsafe-eval' ${webview.cspSource} https://* https://*.posthog.com http://${localServerUrl} http://0.0.0.0:${localPort} 'nonce-${nonce}'`,
618620
`connect-src https://* https://*.posthog.com ws://${localServerUrl} ws://0.0.0.0:${localPort} http://${localServerUrl} http://0.0.0.0:${localPort}`,
619621
]
@@ -629,6 +631,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
629631
<link href="${codiconsUri}" rel="stylesheet" />
630632
<script nonce="${nonce}">
631633
window.IMAGES_BASE_URI = "${imagesUri}"
634+
window.AUDIO_BASE_URI = "${audioUri}"
632635
window.MATERIAL_ICONS_BASE_URI = "${materialIconsUri}"
633636
</script>
634637
<title>Roo Code</title>
@@ -688,6 +691,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
688691
])
689692

690693
const imagesUri = getUri(webview, this.contextProxy.extensionUri, ["assets", "images"])
694+
const audioUri = getUri(webview, this.contextProxy.extensionUri, ["webview-ui", "audio"])
691695

692696
// const scriptUri = webview.asWebviewUri(vscode.Uri.joinPath(this._extensionUri, "assets", "main.js"))
693697

@@ -718,11 +722,12 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
718722
<meta charset="utf-8">
719723
<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
720724
<meta name="theme-color" content="#000000">
721-
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; font-src ${webview.cspSource}; style-src ${webview.cspSource} 'unsafe-inline'; img-src ${webview.cspSource} data:; script-src ${webview.cspSource} 'wasm-unsafe-eval' 'nonce-${nonce}' https://us-assets.i.posthog.com 'strict-dynamic'; connect-src https://openrouter.ai https://api.requesty.ai https://us.i.posthog.com https://us-assets.i.posthog.com;">
725+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; font-src ${webview.cspSource}; style-src ${webview.cspSource} 'unsafe-inline'; img-src ${webview.cspSource} data:; media-src ${webview.cspSource}; script-src ${webview.cspSource} 'wasm-unsafe-eval' 'nonce-${nonce}' https://us-assets.i.posthog.com 'strict-dynamic'; connect-src https://openrouter.ai https://api.requesty.ai https://us.i.posthog.com https://us-assets.i.posthog.com https://file+.vscode-resource.vscode-cdn.net;">
722726
<link rel="stylesheet" type="text/css" href="${stylesUri}">
723727
<link href="${codiconsUri}" rel="stylesheet" />
724728
<script nonce="${nonce}">
725729
window.IMAGES_BASE_URI = "${imagesUri}"
730+
window.AUDIO_BASE_URI = "${audioUri}"
726731
window.MATERIAL_ICONS_BASE_URI = "${materialIconsUri}"
727732
</script>
728733
<title>Roo Code</title>

src/core/webview/__tests__/ClineProvider.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ jest.mock("vscode", () => ({
172172
},
173173
}))
174174

175-
176175
jest.mock("../../../utils/tts", () => ({
177176
setTtsEnabled: jest.fn(),
178177
setTtsSpeed: jest.fn(),
@@ -361,7 +360,7 @@ describe("ClineProvider", () => {
361360

362361
// Verify Content Security Policy contains the necessary PostHog domains
363362
expect(mockWebviewView.webview.html).toContain(
364-
"connect-src https://openrouter.ai https://api.requesty.ai https://us.i.posthog.com https://us-assets.i.posthog.com;",
363+
"connect-src https://openrouter.ai https://api.requesty.ai https://us.i.posthog.com https://us-assets.i.posthog.com https://file+.vscode-resource.vscode-cdn.net;",
365364
)
366365

367366
// Extract the script-src directive section and verify required security elements

webview-ui/src/components/chat/ChatView.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,15 @@ const ChatViewComponent: React.ForwardRefRenderFunction<ChatViewRef, ChatViewPro
150150

151151
// Helper function to get audio URLs that works in both development and Jest environments
152152
const getAudioUrl = (path: string) => {
153-
if (typeof import.meta !== 'undefined') {
154-
return new URL(`/audio/${path}`, import.meta.url).href;
155-
}
156-
// Fallback for Jest environment
157-
return `/audio/${path}`;
153+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
154+
// @ts-ignore
155+
return `${window.AUDIO_BASE_URI}/${path}`
158156
}
159157

160158
// Use the getAudioUrl helper function
161-
const [playNotification] = useSound(getAudioUrl('notification.wav'), soundConfig)
162-
const [playCelebration] = useSound(getAudioUrl('celebration.wav'), soundConfig)
163-
const [playProgressLoop] = useSound(getAudioUrl('progress_loop.wav'), soundConfig)
159+
const [playNotification] = useSound(getAudioUrl("notification.wav"), soundConfig)
160+
const [playCelebration] = useSound(getAudioUrl("celebration.wav"), soundConfig)
161+
const [playProgressLoop] = useSound(getAudioUrl("progress_loop.wav"), soundConfig)
164162

165163
function playSound(audioType: AudioType) {
166164
// Play the appropriate sound based on type

0 commit comments

Comments
 (0)