2

I have a custom exception engine that catches an exceptions, emails details about the exception to me, and then renders a friendly error page. What I would really like to do is to be able to grab a screenshot of the page where the error occurred and attach it to the email.

The problem I have been running into is that the page I want to screenshot is technically the page previous to the current request. So when I have tried inspecting the env hash on an exception, it appears to only have information related to the exception, not the previous page. So if I call render_to_string and use the HTML to generate a screenshot, it ends up being a shot of the friendly error page, rather than the referer page.

Is this possible?

And if it is possible, will it get the page with any JavaScript that was running? For example, if a user opened a JS modal on a page and then got an exception when clicking something inside the modal, I would want the screenshot showing the modal.

supremebeing7
  • 1,073
  • 9
  • 26
  • Rails runs on the server. A screen shot would occur on the client. Rails can not cause the user's device to do a snapshot. Rails can see the HTML being sent, but how that HTML is being rendered on the device is determined by the browser on the device and can be overridden by things the user has configured. You *could* cache all pages being output into a queue and then peek into that, but on a busy site that'd be costly. – the Tin Man Oct 12 '15 at 22:23
  • Couldn't you use something like [Screencap](https://github.com/maxwell/screencap)? The problem with screenshot is that you need to use native tool in order to execute such functionality. Though there are ways to do it using Ruby – Cyzanfar Oct 12 '15 at 22:28
  • @theTinMan I know that how the page is rendered is going to depend on the device and browser of the user, so no matter how this is solved it would be an imperfect solution. I was thinking something that could potentially open a browser (like Selenium does in my feature tests) using the same request the user had made. If I can access the rendered page of the response previous to the request that threw the exception, I could open a selenium or watir browser and screenshot, or use something like screencap like Cyzanfar mentioned – supremebeing7 Oct 13 '15 at 00:13
  • Possible duplicate of [Save screenshot with Watir](http://stackoverflow.com/questions/8369987/save-screenshot-with-watir) – Paul Sweatte Feb 01 '17 at 03:48

0 Answers0