Skip to content

Commit c5c4b9c

Browse files
Copilotalexr00
andcommitted
Fix unmuting audio in video embeds: add media-src CSP and clear muted attribute
Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com>
1 parent 38305d7 commit c5c4b9c

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

src/github/activityBarViewProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ export class PullRequestViewProvider extends WebviewViewBase implements vscode.W
462462
<html lang="en">
463463
<head>
464464
<meta charset="UTF-8">
465-
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-resource: https:; script-src 'nonce-${nonce}'; style-src vscode-resource: 'unsafe-inline' http: https: data:;">
465+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-resource: https:; media-src https:; script-src 'nonce-${nonce}'; style-src vscode-resource: 'unsafe-inline' http: https: data:;">
466466
<meta name="viewport" content="width=device-width, initial-scale=1.0">
467467
468468
<title>Active Pull Request</title>

src/github/createPRViewProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ export abstract class BaseCreatePullRequestViewProvider<T extends BasePullReques
590590
<html lang="en">
591591
<head>
592592
<meta charset="UTF-8">
593-
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-resource: https:; script-src 'nonce-${nonce}'; style-src vscode-resource: 'unsafe-inline' http: https: data:;">
593+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src vscode-resource: https:; media-src https:; script-src 'nonce-${nonce}'; style-src vscode-resource: 'unsafe-inline' http: https: data:;">
594594
<meta name="viewport" content="width=device-width, initial-scale=1.0">
595595
596596
<title>Create Pull Request</title>

webviews/components/comment.tsx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,31 @@ export interface Embodied {
337337
specialDisplayBodyPostfix?: string;
338338
}
339339

340+
/**
341+
* Clears the `muted` state on any `<video>` elements within the given
342+
* container so that users can hear audio in embedded videos. GitHub sets
343+
* `muted` by default on rendered video elements, which causes the audio
344+
* controls to be greyed-out inside VS Code webviews.
345+
*/
346+
function enableVideoAudio(container: HTMLDivElement | null): void {
347+
if (!container) {
348+
return;
349+
}
350+
for (const el of Array.from(container.getElementsByTagName('video'))) {
351+
if (el.hasAttribute('muted')) {
352+
el.removeAttribute('muted');
353+
el.muted = false;
354+
}
355+
}
356+
}
357+
340358
export const CommentBody = ({ comment, bodyHTML, body, canApplyPatch, allowEmpty, specialDisplayBodyPostfix }: Embodied) => {
359+
const bodyContainerRef = useRef<HTMLDivElement>(null);
360+
361+
useEffect(() => {
362+
enableVideoAudio(bodyContainerRef.current);
363+
}, [bodyHTML]);
364+
341365
if (!body && !bodyHTML) {
342366
if (allowEmpty) {
343367
return null;
@@ -350,7 +374,7 @@ export const CommentBody = ({ comment, bodyHTML, body, canApplyPatch, allowEmpty
350374
}
351375

352376
const { applyPatch } = useContext(PullRequestContext);
353-
const renderedBody = <div dangerouslySetInnerHTML={{ __html: bodyHTML ?? '' }} />;
377+
const renderedBody = <div ref={bodyContainerRef} dangerouslySetInnerHTML={{ __html: bodyHTML ?? '' }} />;
354378

355379
const containsSuggestion = ((body || bodyHTML)?.indexOf('```diff') ?? -1) > -1;
356380
const applyPatchButton =

0 commit comments

Comments
 (0)