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

247
Visualizações
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 à 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