Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Only require a "transient" user activation for Web Audio rendering
https://bugs.webkit.org/show_bug.cgi?id=247614 rdar://102364692 Reviewed by Jer Noble. Only require a "transient" user activation for Web Audio rendering instead of having a strict synchronous user gesture requirement. Our behavior was so strict it was confusing Web developers. It was also causing a lot of demo sites to fail in Safari and work in other browsers. For example: - https://googlechromelabs.github.io/web-audio-samples/audio-worklet/basic/hello-audio-worklet/ Such demos require you to click a button but then they use an async function and use `await` before actually starting the audio rendering. * LayoutTests/webaudio/require-transient-activation-expected.txt: Added. * LayoutTests/webaudio/require-transient-activation.html: Added. * Source/WebCore/Modules/webaudio/AudioContext.cpp: (WebCore::shouldDocumentAllowWebAudioToAutoPlay): Canonical link: https://commits.webkit.org/256721@main
- Loading branch information
Showing
3 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
LayoutTests/webaudio/require-transient-activation-expected.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
Tests that starting Web Audio rendering requires a transient user activation. | ||
|
||
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". | ||
|
||
|
||
PASS context.state is "suspended" | ||
node.connect(context.destination) | ||
PASS context.state is "suspended" | ||
PASS navigator.userActivation.isActive is true | ||
PASS resume() promise was resolved | ||
PASS context.state is "running" | ||
PASS navigator.userActivation.isActive is true | ||
PASS successfullyParsed is true | ||
|
||
TEST COMPLETE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<script src="../resources/js-test.js"></script> | ||
<script type="text/javascript" src="resources/audio-testing.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
description("Tests that starting Web Audio rendering requires a transient user activation."); | ||
jsTestIsAsync = true; | ||
|
||
onload = () => { | ||
context = new AudioContext(); | ||
|
||
if (window.internals) | ||
internals.setAudioContextRestrictions(context, 'RequireUserGestureForAudioStart'); | ||
|
||
shouldBeEqualToString('context.state', 'suspended'); | ||
|
||
node = context.createBufferSource(); | ||
evalAndLog('node.connect(context.destination)'); | ||
|
||
shouldBeEqualToString('context.state', 'suspended'); | ||
|
||
runWithKeyDown(function() { | ||
setTimeout(() => { | ||
// We should have transient activation. | ||
shouldBeTrue("navigator.userActivation.isActive"); | ||
context.resume().then(() => { | ||
testPassed("resume() promise was resolved"); | ||
shouldBeEqualToString('context.state', 'running'); | ||
// Transient activation should not have been consumed. | ||
shouldBeTrue("navigator.userActivation.isActive"); | ||
finishJSTest(); | ||
}, () => { | ||
testFailed("resume() promise was rejected"); | ||
finishJSTest(); | ||
}); | ||
}, 10); | ||
}); | ||
}; | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters