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

CookieSameSiteEnum is not exported by happy-dom #1693

Closed
Spixmaster opened this issue Jan 17, 2025 · 6 comments · Fixed by #1699 or #1701
Closed

CookieSameSiteEnum is not exported by happy-dom #1693

Spixmaster opened this issue Jan 17, 2025 · 6 comments · Fixed by #1699 or #1701
Assignees
Labels
bug Something isn't working

Comments

@Spixmaster
Copy link

v16.6.0

CookieSameSiteEnum is not exported by happy-dom. It is needed for .cookieContainer.addCookies().

import {CookieSameSiteEnum} from "happy-dom";

@capricorn86
Copy link
Owner

Thank you for reporting @Spixmaster! 🙂

This has been fixed now in v16.7.1.

I have also made non-mandatory cookie properties optional in CookieContainer.addCookies().

@Spixmaster
Copy link
Author

Spixmaster commented Jan 21, 2025

Thank you very much, @capricorn86 !

CookieSameSiteEnum is exported now.

From my side, the optional properties are not optional. The source code runs with only mandatory properties given but TypeScript complains about missing properties.

import {Browser, type BrowserContext, type BrowserPage} from "happy-dom";

const browser: Browser = new Browser({
    settings: {
        disableErrorCapturing: true,
        disableJavaScriptEvaluation: true
    }
});
const context: BrowserContext = browser.defaultContext;
context.cookieContainer.addCookies([{
    key: "session",
    originURL: new URL("http://localhost:5285"),
    value: "123456"
}]);

Output from the TypeScript language server:

Type '{ key: string; originURL: URL; value: string; }' is missing the following properties from type 'ICookie': domain, path, expires, httpOnly, and 2 more. (FixIt)

@Spixmaster
Copy link
Author

I am not that proficient in TypeScript but it seems to me that the JSON object here misses the declaration as optional.

@Spixmaster
Copy link
Author

Spixmaster commented Jan 21, 2025

I just took a look at the commit 02130fb.

If I understand correcty, there is a distinction between IOptionalCookie and ICookie. I do not understand the reason for that. However, addCookies() has the data type ICookie as the first parameter. Maybe it should have IOptionalCookie instead?

@arpowers
Copy link

FYI this broke our build with
Error: Failed to execute 'addCookies' on 'CookieContainer': The properties 'key' and 'originURL' are required.

code in question:

 beforeEach(() => {
    // Clear cookies and local/session storage before each test
    document.cookie.split(';').forEach((cookie) => {
      document.cookie = cookie.replace(/^ +/, '').replace(/=.*/, `=;expires=${new Date(0).toUTCString()};path=/`)
    })
    localStorage.clear()
    sessionStorage.clear()
  })

@capricorn86
Copy link
Owner

@arpowers I reverted the error check and it will ignore invalid cookies instead (for now at least)

@Spixmaster I have added IOptionalCookie to the ICookieContainer as well now, so it should be correct now

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
3 participants