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

760
Visualizações
Javascript - prompt cause 'document is not focused'

If I add a prompt to the function it works once, but gives the error:

"Uncaught (in promise) DOMException: Document is not focused" at the second attempt.

This is the code:

function site(str) {
  var url = prompt();
  var text = 'The URL is ';
  (async() => {
    await navigator.clipboard.writeText(text + url);
  })();
}
<button class="button" onclick='site()'>URL</button>

I've asked my best friend, Google, but I can't find any solutions. What am I doing wrong?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

It is probably caused by this bug in chromium (Issue #1085949) which makes your prompt call take focus from the Document and not return it when closed. I was not able to reproduce this issue on Safari and Firefox.

The same bug can be reproduced by doing alert instead of prompt followed by navigator.clipboard.writeText.

about 4 years ago · Juan Pablo Isaza Relatório

0

Your JS may be running on a child page. The following works for me:

await parent.navigator.clipboard.writeText('text to copy to Clipboard here.);
about 4 years ago · Juan Pablo Isaza Relatório
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