Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setCookie() doesn't work? #1350

Closed
alixaxel opened this issue Nov 10, 2017 · 4 comments
Closed

setCookie() doesn't work? #1350

alixaxel opened this issue Nov 10, 2017 · 4 comments

Comments

@alixaxel
Copy link
Contributor

Somehow, I'm not able to retrieve cookies previously set with page.setCookie().

Also, is the CROSS_PROCESS_PREFIX argument intended here?

Environment:

  • Puppeteer version: 0.13.0-alpha
  • Platform / OS version: Ubuntu 17.04

What steps will reproduce the problem?

npm run unit -- --filter="should manually set and get cookies"

it('should manually set and get cookies', SX(async function(){
  const cookies = [
    {
      name: 'k1',
      value: 'v1',
      domain: 'httpbin.org',
      path: '/',
      expires: 0,
      size: 4,
      httpOnly: false,
      secure: false,
      session: true,
    },
    {
      name: 'k2',
      value: 'v2',
      domain: 'httpbin.org',
      path: '/',
      expires: 0,
      size: 4,
      httpOnly: false,
      secure: false,
      session: true,
    },
  ];
  await page.setCookie(...cookies);
  await page.goto('https://httpbin.org/cookies');
  expect(await page.cookies()).toEqual(cookies);
}));

What is the expected result?

Test should pass.

What happens instead?

Test fails.

Testing on Node v8.2.1
Started
F

Failures:
1) Page Cookies should manually set and get cookies
  Message:
    Expected $.length = 0 to equal 2.
    Expected $[0] = undefined to equal Object({ name: 'k1', value: 'v1', domain: 'httpbin.org', path: '/', expires: 0, size: 4, httpOnly: false, secure: false, session: true }).
    Expected $[1] = undefined to equal Object({ name: 'k2', value: 'v2', domain: 'httpbin.org', path: '/', expires: 0, size: 4, httpOnly: false, secure: false, session: true }).
  Stack:
    Error: Expected $.length = 0 to equal 2.
    Expected $[0] = undefined to equal Object({ name: 'k1', value: 'v1', domain: 'httpbin.org', path: '/', expires: 0, size: 4, httpOnly: false, secure: false, session: true }).
    Expected $[1] = undefined to equal Object({ name: 'k2', value: 'v2', domain: 'httpbin.org', path: '/', expires: 0, size: 4, httpOnly: false, secure: false, session: true }).
        at /home/alix/Work/puppeteer/test/test.js:3033:36
        at <anonymous>
        at process._tickCallback (internal/process/next_tick.js:188:7)

Ran 1 of 293 specs
1 spec, 1 failure
Finished in 0.738 seconds
@JoelEinbinder
Copy link
Contributor

Can you try not specifying expires: 0? It looks like the cookies are expiring immediately when you reload the page.

@alixaxel
Copy link
Contributor Author

alixaxel commented Nov 15, 2017

@JoelEinbinder

If I set expires to a timestamp sometime in the future and I set session to false, then it works.

I find this behavior a bit strange though, since with nickjs that relies on chrome-remote-interface, the same test yield the behavior I was expecting without needing to modify the values of expire and session. Could this be related to #1342?

@justincy
Copy link

I had the same problem. I was able to keep session set to true and just not set the expires value.

@JoelEinbinder What threw me off was that cookies() was returning an object that had expires set to 0 and session true so I assumed I needed to pass those same values back to setCookie(). In fact I was hoping to just save the entire cookie object and send it back without having to modify it.

aslushnikov pushed a commit that referenced this issue Dec 7, 2017
This roll includes:
- https://crrev.com/520341 DevTools: Network.getCookies should return -1 for null expiry dates
- https://crrev.com/522417 Fix flaky SyntheticMouseEventTest.MouseEventAc

Fixes #1350
@ginuim
Copy link

ginuim commented Aug 22, 2019

I create a new incognito browser context. This won't share cookies/cache with other browser contexts, and it works

const browser = await puppeteer.launch();
// Create a new incognito browser context.
const context = await browser.createIncognitoBrowserContext();
// Create a new page in a pristine context.
const page = await context.newPage();
// Do stuff
await page.setCookie(cookie1, cookie2);
await page.goto('https://example.com');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants