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

129
Visualizações
Generating an offscreen component and turning it into a blob in React

what I am trying to achieve is to have a component which is not visible to the user at any point, then turn it into an image and then get it to the user's clipboard. This is what I have right now.

  const generateImage = () => {
    const component = document.getElementById("component");
    if (component) {
      toBlob(component)
        .then(function (blob: any) {
          const textBlob: any = new Blob(["I am a string"], {
            type: "text/plain",
          });

          navigator.clipboard
            .write([
              new ClipboardItem({
                "image/png": blob,
                "text/plain": textBlob,
              }),
            ])
            .catch((e) => console.log(e));
        })
        .catch((err) => console.log(err));
    }
  };

It works fine when the component is in my sight (even though the image came out kind of shifted to the right? but this probably has to do with my styling), but when I tried something like

position: absolute;
left: -1000%;

It would leave me with an empty clipboard.

I have stumbled upon something like an OffscreenCanvas but I have no idea how to use it properly and maybe there is a cleaner solution to my problem.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I kind of fixed the issue by using another library to first convert the div into a canvas and then such canvas into a blob.

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