brenden / node-webshot

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

document.cookie not filled out by webshot cookie option #76

Closed LorenzGardner closed 10 years ago

LorenzGardner commented 10 years ago

If I use the following JS and call directly using phatomJS

var webPage = require('webpage');
var page = webPage.create();

phantom.addCookie({
   "name": "test",
   "value": "no value",
   "domain": "localhost"
});

page.open('http://localhost/web/status.html', function() {

    page.render('test.png');
    phantom.exit();
});

Then have a local web server that changes the web/status.html page to simply show the contents of document.cookie my screen shot will show my test cookie.

If however instead I use webshot to handle the cross process comunication from inside my node app I can't set the cookie (the screen shot always shows a value of '""' for document.cookie).

node file (test.js) is as such

var options = {
    defaultWhiteBackground: true,
    cookies = [{
       "name": "test",
       "value": "no value",
       "domain": "localhost"
    }]
};

webshot('http://localhost/web/status.html','test.png', options, function(err) {
    // screenshot now saved to outFile iff err==null
});

The documentation implies the cookies object gets passed to phantomJS and to use an array. I tried without the array. i tried with "cookie" instead of "cookies" I've tried several different formats and can't seem to get it to work. I even tried using the custom headers, and while logs of the webserver did in fact show that the request object to the servr contained the cookie header it didn't populate the document.cookie int he phantomJS render.

Am I doing something wrong? Or are cookies not fully supporter by webshot?

LorenzGardner commented 10 years ago

Oh, looks like this is a duplicate of #70