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

208
Views
How can I save a value to the clipboard without using HTML?

I want to save the value 'final' (what I am logging to the console) to the clipboard every time it is updated. I have looked into clipboard.js but cannot find an example of where they didn't use HTML. In all the examples I've seen they press a button in order to do it but I need it to be automatically copied without any HTML. I tried using navigator.clipboard.writeText() but it gave me an error regarding promises and I'm not too sure how to resolve it or if there is a better solution.

const puppeteer = require("puppeteer");
  const url = "https://www.google.com/";
  
  async function StartScraping() {
    await puppeteer
      .launch({
        headless: false,
      })
      .then(async (browser) => {
        const page = await browser.newPage();
  
        await page.setViewport({
          width: 2000,
          height: 800,
        });
  
        page.on("response", async (response) => {
  
         
          if (response.url().includes("Example")) {
            const location = await response.text() 
            let ping1= location.indexOf("Follow:")
            const final = location.substring(ping1, ping1+ 10)
           
            console.log(final);
            //Copy 'final' to clipboard here

            }
  
        });
  
        await page.goto(url, {
          waitUntil: "load",
          timeout: 0,
        });
      });
  }
  StartScraping();
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Yes, you can do this.

You don't need any libraries, you can just do this with one line of code.

navigator.clipboard.writeText("text");

I put it in a function:

function copyText(a){ navigator.clipboard.writeText(a); } copyText("text");

This example uses a button (to execute the function):

function copyText(a) {
  navigator.clipboard.writeText(a);
}
<h1>Copy text on button click</h1>
<p>Copy text without a form input or any extra js libraries</p>
<button onclick="copyText('Hello World!');">Copy</button>

It doesn't work in this snippet, but if you put it into jsfiddle or a w3schools tryit page, it would work.

about 4 years ago · Juan Pablo Isaza Report
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!