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

254
Vistas
Javascript: format text and paste as richtext

I am writing a Chrome extension, and I need to be able to format a string in the clipboard using navigator.clipboard.writeText so that it can be pasted (using Ctrl+V) into a Google Doc or elsewhere as formatted text (bold, or as a hyperlink). I have:

function bolder() {
  navigator.clipboard.writeText(String("text to bold").bold()).then(function() {
    console.log('Async: Copying to clipboard was successful!');
  }, function(err) {
    console.error('Async: Could not copy text: ', err);
  });
}

chrome.action.onClicked.addListener((tab) => {
  chrome.scripting.executeScript({
    target: { tabId: tab.id },
    function: bolder
  });
});

However, when I paste the text, it just pastes as HTML formatted text: i.e. <b>text to bold</b> I get why this works this way, but I can't find a way to format things on the clipboard so they can be pasted as formatted text in Word/Google Docs the way copying/pasting text works on the Windows clipboard.

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