Created
September 16, 2022 19:43
-
-
Save morganney/ef1b103d1dcbb656e45ea074282f7e5d to your computer and use it in GitHub Desktop.
SpeechSynthesis Memory Leak?
This file contains hidden or 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
<!doctype HTML> | |
<html> | |
<head> | |
<title>SpeechSynthesis setInterval Counter</title> | |
</head> | |
<body> | |
<h3>How long until the browser crashes?</h3> | |
<p>On macOS Monterey 12.5.1 (16GB RAM), Chrome, Firefox and Safari all crash at some point (under 200 secs).</p> | |
<button id="start">start</button> | |
<button id="stop">stop</button> | |
<p id="text"></p> | |
<script> | |
let count = 1 | |
let timer = null | |
const synth = window.speechSynthesis | |
const utter = new SpeechSynthesisUtterance() | |
const text = document.getElementById('text') | |
const start = () => { | |
clearInterval(timer) | |
timer = setInterval(() => { | |
utter.text = count.toString() | |
text.innerHTML = `<mark>${count}</mark>` | |
synth.speak(utter) | |
count = count + 1 | |
}, 1100) | |
} | |
const stop = () => { | |
synth.cancel() | |
clearInterval(timer) | |
} | |
utter.rate = 1.5 | |
document.getElementById('start').addEventListener('click', start) | |
document.getElementById('stop').addEventListener('click', stop) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment