maxwell / screencap

A gem to screencap webpages in ruby. Uses Phantom.js under the hood.
MIT License
179 stars 63 forks source link

How to take a screenshot of a tempfile #13

Closed snoblenet closed 9 years ago

snoblenet commented 9 years ago

Apparently, PhantomJS's open() method works with fully formed local file URIs, not just HTTP addresses.

I am trying to take a screenshot of a tempfile, like this:

require 'tempfile'
file = Tempfile.new('foo')
file.write("<html><body><p>using tempfile</p></body></html>")
file.rewind
require 'screencap'
f = Screencap::Fetcher.new(["file://localhost", file.path].join)
screenshot = f.fetch

When I run this, I get an error like:

Screencap::Error: Could not load URL file://localhost/var/folders/k9/vnpft_6d7qs6xmdb9_4svvmw0000gn/T/foo20141105-19881-1ug81de

When I paste the generated URL into Chrome I can view the file no problem.

Any ideas of how to fix this?

I tried forking screencap and commenting out the line that calls 'decodeURIComponent' on the URL, but that didn't work.