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

215
Visualizações
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 Respostas
Responde à pergunta

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 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