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

109
Views
Copiar al portapapeles en un script de contenido

¿Alguien puede explicar cómo puedo escribir en el portapapeles, por favor? He visto muchas maneras, pero parece que no puedo entender cómo. Actualmente se usa el manifiesto v3 y no hay un script background.js.

popup.js (action: download) -> contentscript.js (see below)

 function listener(info) { chrome.runtime.onMessage.addListener( function (request, sender, sendResponse) { if (!request.action) return sendResponse({ err: 'Error: No Request Action' }); switch (request.action) { case "copy": var textCopy = info.links.join(', ').replace(/"/g, '') // Text to Copy (String) navigator.clipboard.writeText(textCopy).then(() => { sendResponse('success') }, () => { sendResponse('failed') }); break; // Other Requests } } ); }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Al menos en el manifiesto v2, este método funciona.


Primero debe agregar el permiso clipboardWrite a su manifiesto:

 ... "permissions": ["clipboardWrite", ... ], ...

Luego haga algo como lo que se respondió aquí: https://stackoverflow.com/a/18455088

La idea es crear un área de texto temporal para colocar el texto en el que luego le permite seleccionar todo el texto dentro con .select() y luego copiarlo con document.execCommand('copy') .

about 4 years ago · Juan Pablo Isaza Report

0

gracias a @cactus12 por la ayuda, ¡aquí está el código que funcionó para mí!

 var textCopy = '' // Text to Copy var copyFrom = document.createElement("textarea"); copyFrom.textContent = `${textCopy}`; document.body.appendChild(copyFrom); copyFrom.select(); document.execCommand(`copy`); copyFrom.blur(); document.body.removeChild(copyFrom);
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!