Skip to content

Instantly share code, notes, and snippets.

@morganney
Created September 16, 2022 19:43
Show Gist options
  • Save morganney/ef1b103d1dcbb656e45ea074282f7e5d to your computer and use it in GitHub Desktop.
Save morganney/ef1b103d1dcbb656e45ea074282f7e5d to your computer and use it in GitHub Desktop.
SpeechSynthesis Memory Leak?
<!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