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

193
Visualizações
Trigger copy in Chrome DevTools

Assume that we through JavaScript have added a method to the global/window object called logToken, that we want to run from the developer console. It's function should be to log a token (string) and copy it to the clipboard. The code exists within a React project and is thus compiled with webpack. How could we achieve this?

We can't use navigator.clipboard.writeText because we get the error "Uncaught (in promise) DOMException: Document is not focused", as the focus is in the developer console.

We can't use copy() because it's only defined in the developer console, not in your JavaScript. It will copy the token to the clipboard, but it will also throw a compilation error upon page load.

Is there any other way around this?

window.logToken = () => {
  const token = 'my magic token';
  
  console.log(token);

  copy(dmdpToken); // works but throws an error on page load
  navigator.clipboard.writeText(token); // doesn't work and throws error
}

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