Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError:Failed to execute 'readAsDataURL' on 'FileReader' : parameter 1 is not of type 'Blob' #162

Open
1 task done
LeeYongDae opened this issue Feb 1, 2024 · 7 comments

Comments

@LeeYongDae
Copy link

LeeYongDae commented Feb 1, 2024

Use case: description, code

Actual behavior (stack traces, console logs etc)

image

Library version

3.2.0

Browsers

  • Chrome 49+
@IDisposable
Copy link
Member

Please create a simple repro on jsfiddle

@lancejpollard
Copy link

lancejpollard commented Feb 6, 2024

I am getting this too.

dom-to-image-more.js:868 Uncaught TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob'.
    at n.onreadystatechange (dom-to-image-more.js:868:33)

The other lib is working: https://www.npmjs.com/package/dom-to-image

const SAMPLE = `\\documentclass[preview]{standalone}
\\usepackage{amsmath}
\\begin{document}
\\begin{equation*}
L = 2
\\end{equation*}
\\end{document}
`

function Body() {
  const files = {}
  const [text, setText] = useState(SAMPLE)
  const [preview, setPreview] = useState<File>()
  const ref = useRef<HTMLDivElement>(null)

  const renderLatex = async () => {
    const blob = (await domtoimage.toBlob(ref.current)) as string
    console.log('done', blob)
    downloadBlob(blob, 'html.png')

    const file = await task.convert({
      input: {
        format: 'tex',
        file: {
          content: text,
        },
      },
      output: {
        format: 'png',
      },
    })

    setPreview(file)
  }

  return (
    <div
      ref={ref}
      className="px-16 flex flex-col gap-16"
    >
      <Field className="h-2-3-screen-minus-nav">
        <Label color="purple">Latex</Label>
        <TextEditor
          language="latex"
          heightClassName="flex-1"
          height="100%"
          theme="purple"
          value={text}
          onChange={v => setText(v ?? '')}
        />
      </Field>
      <div className="flex justify-center p-16">
        <Button onClick={renderLatex}>Render</Button>
      </div>
      {preview && (
        <Field>
          <Label color="blue">Image</Label>
          <BufferImage content={preview} />
        </Field>
      )}
    </div>
  )
}

@IDisposable
Copy link
Member

How about a simple JSFiddle, please?

@nishanbudhathoki2266
Copy link

nishanbudhathoki2266 commented Feb 25, 2024

Looks like there is something wrong with OKLCH color parsing! I am using daisyUI 4 and I am facing the same error while trying to generate a canvas from a part of HTML! Not sure about it though!

@veera-ui
Copy link

I'm using dom-to-image-more plugin for taking screenshot for Web app. I'm facing this issue TypeError:Failed to execute 'readAsDataURL' on 'FileReader' : parameter 1 is not of type 'Blob' , kindly help me to resolve this issue.

@Lruihao
Copy link

Lruihao commented Apr 1, 2024

I am getting this too. When I try to take screenshot for updated icon in my app.

Emm... I try to get you a demo “dom-to-image vs dom-to-image-more”, but this problem is OK in my demo, but I don’t know what to do. Oops!

After constant testing I found the culprit! cacheBust: true, See the demo “dom-to-image vs dom-to-image-more”.

@chris-mcdonald-dev
Copy link

chris-mcdonald-dev commented Apr 30, 2024

Just a bit more info to help us get something reproduceable.

I was getting the same error when there was an img tag nested inside the screenshotted node that had a bad URL as the src. Once all img tags had valid URLs as their sources, the error went away and the export was able to complete successfully.

I couldn't reproduce this in JS Fiddle, but I'll share my setup regardless.
https://jsfiddle.net/crobin/d9s8o6ch/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants