brenden / node-webshot

Easy website screenshots in Node.js
2.12k stars 286 forks source link

New Option - captureSelector #122

Closed nicholasblexrud closed 8 years ago

nicholasblexrud commented 8 years ago

This PR adds a new captureSelector option that allows a user to pass in a selector that will capture the page area containing the provided selector.

Example

webshot('google.com', 'googleLogo.png', {
    captureSelector: '#hplogo'
}, function(err) {

});

This functionality currently exists in casperjs: http://casperjs.readthedocs.org/en/latest/modules/casper.html#captureselector

Note: This is my first stab at a pull request and contributing to project, so any feedback is greatly appreciated. Also, you'll notice some edits to the fixture paths in the test. I was running the test on a PC and it was having issues with the file:// (I believe it was the trailing slashes), so I removed them. I'm new to writing tests too.

This node module has been crucial in a project my team and I have been working on for the past six months. Thanks for the awesome work!

thoughtpalette commented 8 years ago

:+1:

brenden commented 8 years ago

Very cool! Using a selector would be a much easier alternative to defining a bounding box in lots of situations.

Your PR had some merge markers left in it that I had to clean up and I made some formatting changes but it's otherwise fine. Also the changes you made to the file:// paths were causing the tests to break for me on linux so I changed them back. If tests aren't working for you on windows, open an issue and I'll take a look. I never use windows so I definitely haven't done a good job of testing this on windows. That's something I'll work on fixing in the near future.

Thanks for adding this and sorry for the late response.

nicholasblexrud commented 8 years ago

@brenden , thanks for the merge! Any chance you could deploy to NPM? I think that involves bumping the version? Cheers