3 ms·
This is so totally messed up. Having an entire DOM with all the associated scripts running live, just for a thumbnail. What if you want to show a dozen of them?
by jstsch 11y ago
This is so totally messed up. Having an entire DOM with all the associated scripts running live, just for a thumbnail. What if you want to show a dozen of them? What if the user wants to save the image to their machine?
We solve this by taking server side screen shots (currently using slimerjs). We used HTML2Canvas in the past, but it wasn't reliable enough.
It would be great if there was a built-in browser method though, to just get a bitmap of the screen in Javascript. I've heard about security considerations in the past — a prompt for access would not be a problem in our case.
- jensvdh 11y agoI agree, Chrome and Firefox already have the functionality built in because they use screenshots for that "tiles" page when you open your browser. Exposing it using an API would be amazing. But there are most definitely security considerations that would have to be worked around.
- dsp1234 11y agoa prompt for access would not be a problem in our case. Chrome has this (not sure about FF/IE) for extensions. Just add the 'tabs'/'desktopCapture' permission and call the appropriate API[0][1]. [0] - https://developer.chrome.com/extensions/tabs#method-captureVisibleTab https://developer.chrome.com/extensions/tabs#method-captureV... [1] - https://developer.chrome.com/extensions/desktopCapture https://developer.chrome.com/extensions/desktopCapture
- daenz 11y ago> This is so totally messed up. Having an entire DOM with all the associated scripts running live, just for a thumbnail. Agreed. And suppose the "thumbnailed" website had a thumbnail of the parent linking site...
- stanmancan 11y agoJust tested this out, IE and Firefox will only load each page twice, it won't re-load the original page. Chrome goes a bit deeper, it will load each page twice, but then stops.
- AgentME 11y ago>It would be great if there was a built-in browser method though, to just get a bitmap of the screen in Javascript. I've used webkit.js (https://github.com/trevorlinton/webkit.js https://github.com/trevorlinton/webkit.js) to implement a client-side save-chart-to-image feature in an web app. Not really sure if I'd currently recommend it, but the strategy has promise if developed on more. Most people needing to do this right now for arbitrary HTML would probably be better served by having their webapp make a request to a server to run wkhtmltoimage and return the image. The project isn't actively maintained and I never managed to compile it myself, so I wouldn't be able to effectively maintain or extend or fix issues in it. It doesn't have any hooks to call code when it's done rendering something, so I had to experiment and finally I noticed it would call a specific webgl method when it was done, so I would monkey-patch that webgl method to call my code afterward. Then there's the issue that it's a 5mb download (gzipped) to the user's browser. It was only needed for a little-used feature, so I made the file not be requested until the feature is triggered, and then the download progress is shown on a modal. (And then the browser keeps the script cached after loading it once, so future uses of the feature are quicker.) In the end, it works well for my use case here. Some parts of my use case that helped it work was the fact that immediate rendering wasn't necessary (it was fine to make the user wait for it to load), and the fact that it only had to work on HTML that the web app itself generated. webkit.js doesn't handle things like images or remote resources currently, so it wouldn't work well for arbitrary user-provided pages.