Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

cookie not set #11154

Open
jney opened this Issue · 7 comments

6 participants

@jney

I'm trying the addCookie function but when i display page's cookies, the ones i added aren't present. here's the code : https://gist.github.com/jney/5200537
Do i miss something ?

@ariya
Owner

Please always give full information: operating system, PhantomJS version, and many other details.

@jney

this is a 1.8.2 phantomjs running on an uptodate x86_64 Arch linux

jney@architect:~
# uname -am
Linux architect 3.8.4-1-ARCH #1 SMP PREEMPT Wed Mar 20 22:10:25 CET 2013 x86_64 GNU/Linux
jney@architect:~
# phantomjs --version
1.8.2

would you need some other details ?

@JamesMGreene
Collaborator

@jney: I'm assuming you downloaded the binary rather than compiling from source, right?

@jney

exactly, i installed the phantomjs-bin package

@EndangeredMassa

I have the same issue. The only way I can set cookies is to open a page, set cookies, then reload the page.

@salomvary

A little clarification to this: phantom.addCookie() works, WebPage#addCookie() seems to be broken.

Version: 1.9.1

Works:

var WebPage = require('webpage');

phantom.addCookie({
  name: 'phantom_test_cookie',
  value: 'foobar',
  domain: 'google.com'
});

var page = WebPage.create();

page.open('http://www.google.com/robots.txt', function(status) {
  console.log('done');
  phantom.exit();
});

Result:

GET /robots.txt HTTP/1.1.
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.1 Safari/534.34.
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8.
Cookie: phantom_test_cookie=foobar.
Connection: Keep-Alive.
Accept-Encoding: gzip.
Accept-Language: en-US,*.
Host: www.google.com.

Does not work:

var WebPage = require('webpage');

var page = WebPage.create();

page.addCookie({
  name: 'phantom_test_cookie',
  value: 'foobar',
  domain: 'google.com'
});

page.open('http://www.google.com/robots.txt', function(status) {
  console.log('done');
  phantom.exit();
});

Result:

GET /robots.txt HTTP/1.1.
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.9.1 Safari/534.34.
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8.
Connection: Keep-Alive.
Accept-Encoding: gzip.
Accept-Language: en-US,*.
Host: www.google.com.

Requests dumped using:
ngrep -d en1 -W byline port 80 and host www.google.com

After calling WebPage#addCookie() WebPage#cookies is still an empty array. Also tried WebPage#cookies.push() but that resulted in RangeError.

@vohof

@salomvary I tried your working code but it doesn't seem to work: http://stackoverflow.com/questions/20626239/phantom-addcookie-doesnt-work

$ phantomjs --version
1.9.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.