Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for using webshot to retrieve rendered html #99

Open
johnaschroeder opened this issue Feb 23, 2015 · 3 comments
Open

Option for using webshot to retrieve rendered html #99

johnaschroeder opened this issue Feb 23, 2015 · 3 comments

Comments

@johnaschroeder
Copy link

Not really an issue, but I wanted to see if there was interest in integrating some functionality I added in my fork of the project. If so, happy to submit a pull request. If it is too far afield from taking webshots, no worries either.

In addition to returning an image, I needed to capture the rendered html from a page. It's actually really handy to be able to get back the html fully rendered by webkit, vs. something like JSDOM or Cheerio. There are some node wrappers available, and one bridge that seemed too fragile/complicated to put in production, but I don't think there is anything else on github that is this simple to use. So I thought I'd put it out there.

The basic changes are minor:

webshot.js:

-      s.emit('data', new Buffer(''+data, 'base64'));
+      s.emit('data', new Buffer(''+data, 'utf8'));

webshot.phantom.js:

     if (args.streaming === 'false') {
       page.render(args.path);
     } else {
-      console.log(page.renderBase64(args.streamType));
+      console.log(page.content);
     }

     page.close();
@LorenzGardner
Copy link
Contributor

What happens if the page isn't encoded in utf8?

@johnaschroeder
Copy link
Author

I believe what we're emitting is the html page source, ie text. That text is buffered and streamed back to the node function that called it. So even if the html specifies some other wacky encoding in the header or page, isn't that a rendering issue for the browser? utf8 is just telling the buffer to encode the string we need to stream back to webshot instead of a base64 encoded image. Let me know if i've got that wrong though...

@Chazaam
Copy link

Chazaam commented Feb 6, 2017

I johnaschroeder.
Does this solution works well, or do you found a better way?
I want to get the html code and an extract jpeg possibly using just one library...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants