Skip to content

Commit 283aa61

Browse files
authored
Enable autoplay in webviews (microsoft#165784)
For microsoft#134514 This PR allows autoplaying of audio/videos in webviews. However it disables autoplaying of non-muted audio/video without user interaction by setting `autoplayPolicy` in electron. Browsers automatically follow the same behavior
1 parent 2282be5 commit 283aa61

File tree

5 files changed

+8
-7
lines changed

5 files changed

+8
-7
lines changed

src/vs/base/browser/markdownRenderer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ function sanitizeRenderedMarkdown(
360360

361361
export const allowedMarkdownAttr = [
362362
'align',
363+
'autoplay',
363364
'alt',
364365
'class',
365366
'controls',

src/vs/platform/windows/electron-main/windowImpl.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ export class CodeWindow extends Disposable implements ICodeWindow {
221221
enableWebSQL: false,
222222
spellcheck: false,
223223
zoomFactor: zoomLevelToZoomFactor(windowSettings?.zoomLevel),
224+
autoplayPolicy: 'user-gesture-required',
224225
// Enable experimental css highlight api https://chromestatus.com/feature/5436441440026624
225226
// Refs https://github.com/microsoft/vscode/issues/140098
226227
enableBlinkFeatures: 'HighlightAPI',

src/vs/workbench/contrib/webview/browser/pre/index-no-csp.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@
956956
}
957957
newFrame.setAttribute('sandbox', Array.from(sandboxRules).join(' '));
958958

959-
const allowRules = ['cross-origin-isolated;'];
959+
const allowRules = ['cross-origin-isolated;', 'autoplay'];
960960
if (!isFirefox && options.allowScripts) {
961961
allowRules.push('clipboard-read;', 'clipboard-write;');
962962
}

src/vs/workbench/contrib/webview/browser/pre/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta charset="UTF-8">
66

77
<meta http-equiv="Content-Security-Policy"
8-
content="default-src 'none'; script-src 'sha256-jFyDxjOb3XBdk72ii0ggD0YVP/0gCVB58U2Vw6T/7/U=' 'self'; frame-src 'self'; style-src 'unsafe-inline';">
8+
content="default-src 'none'; script-src 'sha256-6s2fEapj0jmA7ZDjzz23Uv4xLlM7KX3p9DYidJX7Zmk=' 'self'; frame-src 'self'; style-src 'unsafe-inline';">
99

1010
<!-- Disable pinch zooming -->
1111
<meta name="viewport"
@@ -957,7 +957,7 @@
957957
}
958958
newFrame.setAttribute('sandbox', Array.from(sandboxRules).join(' '));
959959

960-
const allowRules = ['cross-origin-isolated;'];
960+
const allowRules = ['cross-origin-isolated;', 'autoplay;'];
961961
if (!isFirefox && options.allowScripts) {
962962
allowRules.push('clipboard-read;', 'clipboard-write;');
963963
}

src/vs/workbench/contrib/webview/browser/webviewElement.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,11 @@ export class WebviewElement extends Disposable implements IWebview, WebviewFindD
450450
element.className = `webview ${options.customClasses || ''}`;
451451
element.sandbox.add('allow-scripts', 'allow-same-origin', 'allow-forms', 'allow-pointer-lock', 'allow-downloads');
452452

453-
const allowRules = ['cross-origin-isolated;'];
453+
const allowRules = ['cross-origin-isolated', 'autoplay'];
454454
if (!isFirefox) {
455-
allowRules.push('clipboard-read;', 'clipboard-write;');
456-
element.setAttribute('allow', 'clipboard-read; clipboard-write; cross-origin-isolated;');
455+
allowRules.push('clipboard-read', 'clipboard-write');
457456
}
458-
element.setAttribute('allow', allowRules.join(' '));
457+
element.setAttribute('allow', allowRules.join('; '));
459458

460459
element.style.border = 'none';
461460
element.style.width = '100%';

0 commit comments

Comments
 (0)