Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

178
Visualizações
Using a button but receiving: DOMException: play() failed because the user didn't interact with the document first

I am currently getting this error on Google Chrome when trying to run a JS function that plays sound on a button click.

here is the code:

index.html

<button type="button" id="test-button">Test C Key</button>
index.js

function playNote() {
  let audio = new Audio('sounds/c-major.wav')
  audio.play()
  }

document.getElementById('test-button').addEventListener('click', playNote())

Error:

index.js:3 Uncaught (in promise) DOMException: play() failed because the user didn't interact with the document first. 

Any advice on how to overcome this? I understand that it can't play automatically but I am using a button click for trigger.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda