question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Canvas#toDataURL() returns image data url string with quotes included

See original GitHub issue

Canvas#toDataURL() returns a string like "\"data:image/png;base64,iVB...\"".

It seems caused by the payload being JSON.stringify() at web view side: https://github.com/iddan/react-native-canvas/blob/master/src/webview.js#L88 and get returned directly at React Native side: https://github.com/iddan/react-native-canvas/blob/master/src/Canvas.js#L76

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:5
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
fabiancookcommented, Jul 7, 2019

Please can we document this as it isn’t the same signature as what is on the web.

Because of me just ignoring the quotes when I read them in the console, I didn’t notice the extra quotes D: Took me a while to figure out that one.

1reaction
mikepjcommented, Nov 24, 2021

I just ran into this issue after spending a few hours debugging. I worked around it by replacing the quotes in the string returned:

imageData = await canvas.toDataURL();
imageData = imageData.replace(/^"|"$/g, ``);

I’m not sure what the best solution is here. Singling out the toDataURL call when choosing whether to stringify the response message in the code @rocwind linked above doesn’t feel right.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HTMLCanvasElement.toDataURL() - Web APIs | MDN
toDataURL() method returns a data URL containing a representation of the image in the format specified by the type parameter.
Read more >
Blank image when executing canvas.toDataUrl()
So after much trawling through StackOverflow I found the function drawScene() which (somehow?) force toDataURL() to return the image data as ...
Read more >
Convert Image to Data URI with JavaScript - Tutorialspoint
In here it is explained how to make a canvas element, load an image into it, and use toDataURL() to display the string...
Read more >
node-canvas - npm
Image #src. img.src: string|Buffer. As in browsers, img.src can be set to a data: URI or a remote URL. In addition, node-canvas allows ......
Read more >
The HTML5 Canvas Handbook - Bucephalus.org
toDataURL() that translates the full content of the given canvas into code for an image file (PNG or ... Returns a data: URL...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found