Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

194
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda