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

125
Views
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 answers
Answer question

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