Skip to content

cookieContainer shows inconsistent behaviour #1799

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

Open
garysassano opened this issue Apr 11, 2025 · 0 comments
Open

cookieContainer shows inconsistent behaviour #1799

garysassano opened this issue Apr 11, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@garysassano
Copy link

garysassano commented Apr 11, 2025

I've been testing cookieContainer across various websites in multiple scenarios, and in my experience, it's highly unreliable. The results from the getCookies() method consistently differ from the actual cookies present after visiting a page in a real browser.

index.ts

import { Browser } from "happy-dom";

const browser = new Browser();
const page = browser.newPage();

try {
  const url = "https://www.example.com/";
  console.log(`Navigating to ${url}...`);
  await page.goto(url);

  const cookies = await page.context.cookieContainer.getCookies(new URL(url));
  console.log("\n--- Cookies ---");
  console.log(JSON.stringify(cookies, null, 2));
  console.log("---------------");
} catch (error) {
  console.error("Error occurred:", error);
} finally {
  console.log("\nClosing browser...");
  await browser.close();
  console.log("Browser closed.");
}
First run
Navigating to https://www.amazon.com/...

--- Cookies ---
[
  {
    "key": "skin",
    "originURL": "https://www.amazon.com/",
    "value": "noskin",
    "domain": ".amazon.com",
    "path": "/",
    "expires": null,
    "httpOnly": false,
    "secure": false,
    "sameSite": "Lax"
  }
]
---------------

Closing browser...
Browser closed.
Second run
Navigating to https://www.amazon.com/...

--- Cookies ---
[
  {
    "key": "session-id",
    "originURL": "https://www.amazon.com/",
    "value": "135-2546199-2440702",
    "domain": ".amazon.com",
    "path": "/",
    "expires": "2026-04-11T00:40:36.000Z",
    "httpOnly": false,
    "secure": true,
    "sameSite": "Lax"
  },
  {
    "key": "session-id-time",
    "originURL": "https://www.amazon.com/",
    "value": "2082787201l",
    "domain": ".amazon.com",
    "path": "/",
    "expires": "2026-04-11T00:40:36.000Z",
    "httpOnly": false,
    "secure": true,
    "sameSite": "Lax"
  },
  {
    "key": "i18n-prefs",
    "originURL": "https://www.amazon.com/",
    "value": "USD",
    "domain": ".amazon.com",
    "path": "/",
    "expires": "2026-04-11T00:40:36.000Z",
    "httpOnly": false,
    "secure": false,
    "sameSite": "Lax"
  },
  {
    "key": "sp-cdn",
    "originURL": "https://www.amazon.com/",
    "value": "\"L5Z9:IT\"",
    "domain": ".amazon.com",
    "path": "/",
    "expires": "2026-04-11T00:40:36.000Z",
    "httpOnly": true,
    "secure": true,
    "sameSite": "Lax"
  },
  {
    "key": "skin",
    "originURL": "https://www.amazon.com/",
    "value": "noskin",
    "domain": ".amazon.com",
    "path": "/",
    "expires": null,
    "httpOnly": false,
    "secure": false,
    "sameSite": "Lax"
  }
]
---------------

Closing browser...
Browser closed.
Real browser cookies

Image

@garysassano garysassano added the bug Something isn't working label Apr 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant