brenden / node-webshot

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

Add login example #62

Open matchdav opened 10 years ago

matchdav commented 10 years ago

I'd like a more straightforward way of passing webshot the session credentials, for example, I want to take a screenshot of a working document on save. Right now I just get a login screen.

Perhaps a working example of how to pass phantom the info.

lukepolo commented 9 years ago

I've done this , but it also relies on your framework to correctly take the cookie (aka if its encrypted)

Here is an example :

 var options = 
    {
    screenSize: {
        width: 1500
    },
        shotSize: {
            height: 'all',
            quality : 85
        },
        renderDelay: !req.query.delay ? delay : req.query.delay,
    phantomConfig: {
        'ignore-ssl-errors': 'true'
    },
    cookies: [
        {
        name: 'cookie_name',
        value: 'cookie_value',
        path: '/',
        domain: '.yourdomain.com'
        }
    ]
    };
jhenriquez commented 9 years ago

Hey @lukepolo @matchdav I've not been able to get this to work. Maybe you could give me some advice.

In my case passport is my framework. I'm setting the cookies but they're being ignored. I'm not sure how to dig what is going on, is passport ignoring the cookie? Could I be using the wrong cookie? Was any of you using passport when you got this working, if you did.

These are the options I'm using:

var options = {
      cookies: [
        {
          name: 'session',
          value: req.cookies.session,
          path: '/',
          domain: 'localhost'
        }
      ]
    };

Any advice will be greatly appreciated!

lukepolo commented 9 years ago

So passport is probably using encrypted cookies, make sure your cookie that your passing is also encrypted

jhenriquez commented 9 years ago

Right now, I'm taking the cookies in the express request adding them to the cookies array.

If it's encrypted should be encrypted there as well. I'll ask the passport guys for advice.

Thanks!

On Thu, Jul 9, 2015, 9:32 AM Luke Policinski notifications@github.com wrote:

So passport is probably using encrypted cookies, make sure your cookie that your passing is also encrypted

— Reply to this email directly or view it on GitHub https://github.com/brenden/node-webshot/issues/62#issuecomment-119966406 .

lukepolo commented 9 years ago

Yah if its encrypted it should be encrypted there as well, since its basically simulating a client. You can actually grab the cookie from your browser and it should work