streptomycin 16 hours ago

I've been using html2canvas for a long time in https://play.basketball-gm.com/ so I gave your library a try. It was much slower (I know your README has benchmarks saying the opposite so idk) and the result looked a lot worse.

html2canvas: https://i.imgur.com/zfSwNR1.png

snapdom: https://i.imgur.com/FxowTzp.png

Also I recommend putting the npm package name clearly in your README. I guess I don't really know what other people are doing these days, but I think most people are like me and consume packages like this from npm rather than a <script> tag.

  • tinchox6 16 hours ago

    Thank you for testing it out and sharing the screenshots!

    I’ve run some performance tests using Vitest Bench, and SnapDOM was faster. I also created a few manual demos, and SnapDOM won in both speed and accuracy.

    That said, I still need to run more real-world tests. So, thanks again for your help!

    • hirako2000 15 hours ago

      How can svg be faster, and especially more accurate (lets throw some IMG or CSS shadows for fun) than canvas?

      • kaoD 14 hours ago

        You can embed HTML in an SVG via foreignObject. Seems like that's exactly what the library is doing[0].

        Whether that's faster or more reliable, I don't know. Seems likely to render different depending on where you view the SVG (especially out of browsers).

        [0]: https://github.com/search?q=repo%3Azumerlab%2Fsnapdom%20fore...

  • tinchox6 16 hours ago

    I added to README the npm / yarn reference. Thanks!

jdiff 16 hours ago

Capturing HTML as scalable SVGs is huge, how do you manage condensing all of CSS and its quirks into an SVG? Do you only support a subset of styling properties and rely on the browser to calculate layouts for you?

  • tinchox6 16 hours ago

    I was upset about the size of generated svg file because at first all styles were inlined in each element. So I created a function to make mini css classes (.c1, c2, c3,...) So the final size is quite small.

krebby 16 hours ago

How does this compare to something like the the Media Capture API? Looks like this uses `canvas.toDataURL()` which can be slow to serialize compared to `toBlob` or `canvas.captureStream(0).getVideoTracks()`

I've been using CropTarget.fromElement with a CaptureController: https://gist.github.com/akre54/e93ab2ce27999aecb109e38085f2e...

G_o_D 7 hours ago

It doesnt load, snapdom dont appear in my devtools had to copy paste script

Plus it just struck at pending promise dont work

Plus css is messed up, i cant call it a snapshot, if it dont look same

domtoimage lib works for me and is fast whole html body node captured within second

ashishact 14 hours ago

Image in the readme would really be helpful. In fact anytime there is a visual output it makes sense to put an image. Thanks for creating this though - Will give it a try for an upcoming project.

  • tinchox6 13 hours ago

    Thank you for the suggestion!

simonw 9 hours ago

Tiny feature request: snapdom.toJpg(el) appears to return a JPEG image where the background color for any transparent areas is set to black - it would be useful to be able to set that to another color (I needed it to be white).

darrenf 14 hours ago

I’ve been writing a browser extension recently, and part of the functionality I want is to export part of a view as an image, shareable for the socials. I wanted to use html2canvas, but the docs explicitly advise against using it in a browser extension. Would snapDOM be suitable for inclusion in an extension?

  • genewitch an hour ago

    Firefox has screenshot that auto-picks elements, or you can click and drag a crop, or you can save the whole page. That and ad nauseam are the reason I use firefox; that singlefile also works is great (single html file dump of a web page, somehow).

  • tinchox6 13 hours ago

    Sincerely, I don't know if snapdom would work on a browser extension. I've never tested it on this scenery

maxloh 15 hours ago

Maybe add a function to convert to PDF? I've always dreamed of converting an element or the document body to a long-scrolling PDF. I tried to implement it with Playwright Python, but I had no luck. The resulting PDF height is messed up.

  • tinchox6 13 hours ago

    Its a bit out of scope right now, but I thing it would be possible using some external libraries such as jsPDF or svg2pdf.js

rs186 13 hours ago
  • tinchox6 13 hours ago

    It is pretty the same idea. There are many good solutions like dom-to-imge-more: the battle tested html2canvas, dom-to-image, modern-screenshot, etc. SnapDom is focused on avoiding long-taks whenever is possible because was designed to a zoomble UI engine that needs the capture doesnt affect the transition. But this is the first public version and there many things to adjust.

braebo 14 hours ago

I found puppeteer or playwright to be good at this with their screenshot method. I made a cli tool for this recently that worked quite well.

  • tinchox6 14 hours ago

    Yes they are so good. But in my case I need to work only on the client side

badmonster 16 hours ago

Does snapDOM support capturing elements with CSS animations in their current frame, or does it only capture static states?

  • tinchox6 16 hours ago

    Yes it capture elements with css animations in theirr current frame. It isnt't work for animted gifs. And I have to test js animations engines

nikeee 15 hours ago

Does it work with some DOM polyfill in Node.js?

andrewstuart 16 hours ago

Screenshots on the GitHub would be great.

  • Eduard 16 hours ago

    Not only screenshots, but also actual results. As I understand the short description, this tool allows to transform a website's current visual state into an SVG.

andrewstuart 16 hours ago

Why not do it at the back end where you can literally snapshot node to png.