News for hackers. Stuff that matters.
Re:Simulating Website Thumbnails Using Iframes by jstsch on Monday January 18, 2016 @01:16PM (#10925866)
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.

Re:Simulating Website Thumbnails Using Iframes by daenz on Monday January 18, 2016 @01:50PM (#10926065)
> 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...

Re:Simulating Website Thumbnails Using Iframes by stanmancan on Monday January 18, 2016 @02:48PM (#10926450)
Just 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.
Re:Simulating Website Thumbnails Using Iframes by jensvdh on Monday January 18, 2016 @01:20PM (#10925884)
I 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.

Re:Simulating Website Thumbnails Using Iframes by AgentME on Monday January 18, 2016 @04:09PM (#10926962)
>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) 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.

Re:Simulating Website Thumbnails Using Iframes by dsp1234 on Monday January 18, 2016 @01:40PM (#10926007)
a 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-captureV...

[1] - https://developer.chrome.com/extensions/desktopCapture

Re:Simulating Website Thumbnails Using Iframes by daguava on Monday January 18, 2016 @02:02PM (#10926148)
This demonstrates some cool CSS properties, but please never do this in production.

The resource overhead of just one "thumbnail" will be insane, and your mobile users will hate you.

This "thumbnail" can then do anything a website can, like alert dialogs and location requests.

Re:Simulating Website Thumbnails Using Iframes by niutech on Monday January 18, 2016 @02:55PM (#10926483)
This is madness! Loading the whole page just to show an thumbnail? Don't do this ever. Better use the free http://web-capture.net/ or http://pagepeeker.com/
Re:Simulating Website Thumbnails Using Iframes by SchizoDuckie on Monday January 18, 2016 @03:14PM (#10926604)
Re:Simulating Website Thumbnails Using Iframes by lobster_johnson on Friday January 22, 2016 @12:19PM (#10954065)
That returns a blank image for many of the URLs I tried. Is it queueing up for rendering, or is it not rendering unpopular sites?
Re:Simulating Website Thumbnails Using Iframes by yid on Monday January 18, 2016 @12:58PM (#10925749)
The interesting thing here is that you can set the iframe size to a regular desktop-like size, and then use CSS3 transforms to scale the rendered page down to thumbnail size.
Re:Simulating Website Thumbnails Using Iframes by rossta on Monday January 18, 2016 @01:30PM (#10925950)
I believe a caveat with this technique is that it won't work for sites that send the X-Frame-Options header as SAMEORIGIN in supporting browsers.
Re:Simulating Website Thumbnails Using Iframes by tomhallett on Monday January 18, 2016 @01:45PM (#10926035)
Agreed. Another caveat: this technique won't work if the website has iframe busting javascript code.

The iframe will reset the source of the top level page and will cripple your app.

If you control the domains you are embedding this won't be a problem, but if you don't - then it's a risk to be aware of.

Re:Simulating Website Thumbnails Using Iframes by leonkenneth on Monday January 18, 2016 @02:40PM (#10926401)
If your target browsers support it, you can use the `sandbox` attribute and avoid supplying the `allow-top-navigation` flag to prevent this behaviour.

Granted, this won't prevent other framebusting techniques such as checking the parent before rendering.

Re:Simulating Website Thumbnails Using Iframes by janoelze on Monday January 18, 2016 @03:13PM (#10926596)
… and expose the user to 5000 and a half third party tracking scripts in the process. please don't.
Re:Simulating Website Thumbnails Using Iframes by vortico on Monday January 18, 2016 @06:19PM (#10927738)
So basically you think the cost of generating a thumbnail of a website (likely less than 1/100 of a cent) is too expensive, so you make the client do it and destroy usability in the process by making the page slow to a crawl. Remember, usability has a value, since you wouldn't make the website in the first place if people couldn't use it.
Re:Simulating Website Thumbnails Using Iframes by jensvdh on Monday January 18, 2016 @01:18PM (#10925873)
While this is an interesting approach I would not recommend this for anything other than desktop websites, where bandwidth and performance are less of an issue, simply because you are loading every single "Thumbnail" as a full webpage inside those iframes. Downloading all the associated scripts, stylesheets and other resources.