Ferrari/grunt-autoshot — pull request #8 by wamberg (2014-01-08 20:20:26+00:00)
Title: Allow an options.preCreate function to be run on a PhantomJS WebPage instance

This pull request allows us to access the [WebPage](https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage) before generating the screenshot. This is helpful to me because I want to add cookies and access pages that require authentication. With this pull request I can use something like the following Gruntfile.js:

```javascript
module.exports = function(grunt) {
grunt.initConfig({
autoshot: {
public: {
options: {
path: '/tmp',
remote: {
files: [
{ src: 'http://localhost:8000/', dest: 'login.png' }
]
},
local: null,
preCreate: null,
viewport: [
'320x480',
'600x1024',
'1024x768',
'1280x800',
'1440x900'
]
}
},
authenticated: {
options: {
path: '/tmp',
remote: {
files: [
{ src: 'http://localhost:8000/', dest: 'dashboard.png' }
]
},
local: null,
preCreate: function(ph) {
ph.addCookie({
'name': 'sessionid',
'value': 'v48054jkxxjwtb7cmzwa6iaqimjzs0ax',
'domain': 'localhost',
'path': '/',
'httponly': true,
'secure': false,
'expires': (new Date()).getTime() + (1000 * 60 * 60)
});
},
viewport: [
'320x480',
'600x1024',
'1024x768',
'1280x800',
'1440x900'
]
}
}
}
});
grunt.loadNpmTasks('grunt-autoshot');
};
```

* grunt autoshot:public - takes a screenshot of localhost:8000 as normal
* grunt autoshot:authenticated - adds a cookie which gives us access to the dashboard at localhost:8000 which requires authentication

What you do in preCreate (how you get the cookie value, for example) is up to you.