Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!