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 · 8 comments · Fixed by #1699 or #1701
Closed

CookieSameSiteEnum is not exported by happy-dom #1693

Spixmaster opened this issue Jan 17, 2025 · 8 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

@Spixmaster
Copy link
Author

@capricorn86 Thank you very much. It works. However, I do not understand in 89e8820 the reason the ignore invalid cookies. The consequence of an exception being thrown was completely justified and expected behaviour. Simply not adding them, gives falss impressions that cookies were set and does not even solve the issue from @arpowers .

@capricorn86
Copy link
Owner

@capricorn86 Thank you very much. It works. However, I do not understand in 89e8820 the reason the ignore invalid cookies. The consequence of an exception being thrown was completely justified and expected behaviour. Simply not adding them, gives falss impressions that cookies were set and does not even solve the issue from @arpowers .

You are right @Spixmaster, it makes sense to throw an error there, but it requires document.cookie to handle when a cookie is invalid before sending it in to CookieContainer and therefore it requires further investigation. document.cookie should never throw an error for invalid strings. For now I just wanted to make sure that it doesn't break for people.

DennisRasey pushed a commit to DennisRasey/forgejo that referenced this issue Feb 1, 2025
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [happy-dom](https://github.com/capricorn86/happy-dom) | devDependencies | minor | [`16.3.0` -> `16.8.1`](https://renovatebot.com/diffs/npm/happy-dom/16.3.0/16.8.1) |

---

### Release Notes

<details>
<summary>capricorn86/happy-dom (happy-dom)</summary>

### [`v16.8.1`](https://github.com/capricorn86/happy-dom/releases/tag/v16.8.1)

[Compare Source](capricorn86/happy-dom@v16.8.0...v16.8.1)

##### 👷‍♂️ Patch fixes

-   Handle non-string values gracefully when removing an attribute - By **[@&#8203;OlaviSau](https://github.com/OlaviSau)** in task [#&#8203;1706](capricorn86/happy-dom#1706)

### [`v16.8.0`](https://github.com/capricorn86/happy-dom/releases/tag/v16.8.0)

[Compare Source](capricorn86/happy-dom@v16.7.3...v16.8.0)

##### 🎨 Features

-   Add support for `insertRow()` and `deleteRow()` to `HTMLTableSectionElement` - By **[@&#8203;christiango](https://github.com/christiango)** in task [#&#8203;1708](capricorn86/happy-dom#1708)

### [`v16.7.3`](https://github.com/capricorn86/happy-dom/releases/tag/v16.7.3)

[Compare Source](capricorn86/happy-dom@v16.7.2...v16.7.3)

##### 👷‍♂️ Patch fixes

-   Removes space from directory name that prevents the repo to be cloned on MS Windows - By **[@&#8203;kleinfreund](https://github.com/kleinfreund)** in task [#&#8203;1703](capricorn86/happy-dom#1703)

### [`v16.7.2`](https://github.com/capricorn86/happy-dom/releases/tag/v16.7.2)

[Compare Source](capricorn86/happy-dom@v16.7.1...v16.7.2)

##### 👷‍♂️ Patch fixes

-   Ignore invalid cookies in CookieContainer - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1693](capricorn86/happy-dom#1693)

### [`v16.7.1`](https://github.com/capricorn86/happy-dom/releases/tag/v16.7.1)

[Compare Source](capricorn86/happy-dom@v16.7.0...v16.7.1)

##### 👷‍♂️ Patch fixes

-   Adds `ICookie`, `IOptionalCookie`, `CookieSameSiteEnum` and `IVirtualServer` as exports to the index file - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1693](capricorn86/happy-dom#1693)
-   Makes non-mandatory cookie properties optional in `CookieContainer.addCookies()` - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1693](capricorn86/happy-dom#1693)

### [`v16.7.0`](https://github.com/capricorn86/happy-dom/releases/tag/v16.7.0)

[Compare Source](capricorn86/happy-dom@v16.6.0...v16.7.0)

##### 🎨 Features

-   Adds support for simulating local HTTP servers that serves files from the local file system - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1688](capricorn86/happy-dom#1688)
    -   Read more about virtual servers in the [Wiki](https://github.com/capricorn86/happy-dom/wiki/IVirtualServer)

### [`v16.6.0`](https://github.com/capricorn86/happy-dom/releases/tag/v16.6.0)

[Compare Source](capricorn86/happy-dom@v16.5.3...v16.6.0)

##### 🎨 Features

-   Adds support for subsequent sibling combinator to `querySelector()`, `querySelectorAll()` and `matches()` (e.g. ".a ~ .b") - By **[@&#8203;karpiuMG](https://github.com/karpiuMG)** in task [#&#8203;1683](capricorn86/happy-dom#1683)

### [`v16.5.3`](https://github.com/capricorn86/happy-dom/releases/tag/v16.5.3)

[Compare Source](capricorn86/happy-dom@v16.5.2...v16.5.3)

##### 👷‍♂️ Patch fixes

-   Fixes problem with encoding and decoding attribute values in HTML - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1678](capricorn86/happy-dom#1678)
-   Fixes issue where it was not possible to query selector by class when the attribute value had line breaks in it - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1678](capricorn86/happy-dom#1678)

### [`v16.5.2`](https://github.com/capricorn86/happy-dom/releases/tag/v16.5.2)

[Compare Source](capricorn86/happy-dom@v16.5.1...v16.5.2)

##### 👷‍♂️ Patch fixes

-   `Event.target` should be the target element after an event has been dispatched - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1529](capricorn86/happy-dom#1529)

### [`v16.5.1`](https://github.com/capricorn86/happy-dom/releases/tag/v16.5.1)

[Compare Source](capricorn86/happy-dom@v16.5.0...v16.5.1)

##### 👷‍♂️ Patch fixes

-   Fixes issue where `Comment`, `Text` and `DocumentFragment` are not instances of their corresponding property on `Window` - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1577](capricorn86/happy-dom#1577)

### [`v16.5.0`](https://github.com/capricorn86/happy-dom/releases/tag/v16.5.0)

[Compare Source](capricorn86/happy-dom@v16.4.3...v16.5.0)

##### 🎨 Features

-   Adds property `GlobalRegistrator.isRegistered` - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1670](capricorn86/happy-dom#1670)

### [`v16.4.3`](https://github.com/capricorn86/happy-dom/releases/tag/v16.4.3)

[Compare Source](capricorn86/happy-dom@v16.4.2...v16.4.3)

##### 👷‍♂️ Patch fixes

-   Adds null check for if browser frame is available in `Response` during tear down of the `Window` - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1669](capricorn86/happy-dom#1669)

### [`v16.4.2`](https://github.com/capricorn86/happy-dom/releases/tag/v16.4.2)

[Compare Source](capricorn86/happy-dom@v16.4.1...v16.4.2)

##### 👷‍♂️ Patch fixes

-   Support using URL as an object for URL:s when using the Browser API - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1664](capricorn86/happy-dom#1664)

### [`v16.4.1`](https://github.com/capricorn86/happy-dom/releases/tag/v16.4.1)

[Compare Source](capricorn86/happy-dom@v16.4.0...v16.4.1)

##### 👷‍♂️ Patch fixes

-   Fixes issue where HTML assigned to `document.documentElement.innerHTML` isnt parsed correctly since v16 - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1663](capricorn86/happy-dom#1663)

### [`v16.4.0`](https://github.com/capricorn86/happy-dom/releases/tag/v16.4.0)

[Compare Source](capricorn86/happy-dom@v16.3.0...v16.4.0)

##### 🎨 Features

-   Allow fetch to be intercepted and modified by sending in an interceptor as a setting - By **[@&#8203;OlaviSau](https://github.com/OlaviSau)** in task [#&#8203;1502](capricorn86/happy-dom#1502)
    -   Read more about this in the Wiki at [IFetchInterceptor](https://github.com/capricorn86/happy-dom/wiki/IFetchInterceptor)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "* 0-3 1 * *" (UTC), Automerge - "* 0-3 * * *" (UTC).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xMzYuMSIsInVwZGF0ZWRJblZlciI6IjM5LjEzNi4xIiwidGFyZ2V0QnJhbmNoIjoiZm9yZ2VqbyIsImxhYmVscyI6WyJkZXBlbmRlbmN5LXVwZ3JhZGUiLCJ0ZXN0L25vdC1uZWVkZWQiXX0=-->

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6757
Reviewed-by: Earl Warren <[email protected]>
Co-authored-by: Renovate Bot <[email protected]>
Co-committed-by: Renovate Bot <[email protected]>
humaton pushed a commit to fedora-infra/forgejo-deployment-images that referenced this issue Feb 18, 2025
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [happy-dom](https://github.com/capricorn86/happy-dom) | devDependencies | minor | [`16.3.0` -> `16.8.1`](https://renovatebot.com/diffs/npm/happy-dom/16.3.0/16.8.1) |

---

### Release Notes

<details>
<summary>capricorn86/happy-dom (happy-dom)</summary>

### [`v16.8.1`](https://github.com/capricorn86/happy-dom/releases/tag/v16.8.1)

[Compare Source](capricorn86/happy-dom@v16.8.0...v16.8.1)

##### 👷‍♂️ Patch fixes

-   Handle non-string values gracefully when removing an attribute - By **[@&#8203;OlaviSau](https://github.com/OlaviSau)** in task [#&#8203;1706](capricorn86/happy-dom#1706)

### [`v16.8.0`](https://github.com/capricorn86/happy-dom/releases/tag/v16.8.0)

[Compare Source](capricorn86/happy-dom@v16.7.3...v16.8.0)

##### 🎨 Features

-   Add support for `insertRow()` and `deleteRow()` to `HTMLTableSectionElement` - By **[@&#8203;christiango](https://github.com/christiango)** in task [#&#8203;1708](capricorn86/happy-dom#1708)

### [`v16.7.3`](https://github.com/capricorn86/happy-dom/releases/tag/v16.7.3)

[Compare Source](capricorn86/happy-dom@v16.7.2...v16.7.3)

##### 👷‍♂️ Patch fixes

-   Removes space from directory name that prevents the repo to be cloned on MS Windows - By **[@&#8203;kleinfreund](https://github.com/kleinfreund)** in task [#&#8203;1703](capricorn86/happy-dom#1703)

### [`v16.7.2`](https://github.com/capricorn86/happy-dom/releases/tag/v16.7.2)

[Compare Source](capricorn86/happy-dom@v16.7.1...v16.7.2)

##### 👷‍♂️ Patch fixes

-   Ignore invalid cookies in CookieContainer - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1693](capricorn86/happy-dom#1693)

### [`v16.7.1`](https://github.com/capricorn86/happy-dom/releases/tag/v16.7.1)

[Compare Source](capricorn86/happy-dom@v16.7.0...v16.7.1)

##### 👷‍♂️ Patch fixes

-   Adds `ICookie`, `IOptionalCookie`, `CookieSameSiteEnum` and `IVirtualServer` as exports to the index file - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1693](capricorn86/happy-dom#1693)
-   Makes non-mandatory cookie properties optional in `CookieContainer.addCookies()` - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1693](capricorn86/happy-dom#1693)

### [`v16.7.0`](https://github.com/capricorn86/happy-dom/releases/tag/v16.7.0)

[Compare Source](capricorn86/happy-dom@v16.6.0...v16.7.0)

##### 🎨 Features

-   Adds support for simulating local HTTP servers that serves files from the local file system - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1688](capricorn86/happy-dom#1688)
    -   Read more about virtual servers in the [Wiki](https://github.com/capricorn86/happy-dom/wiki/IVirtualServer)

### [`v16.6.0`](https://github.com/capricorn86/happy-dom/releases/tag/v16.6.0)

[Compare Source](capricorn86/happy-dom@v16.5.3...v16.6.0)

##### 🎨 Features

-   Adds support for subsequent sibling combinator to `querySelector()`, `querySelectorAll()` and `matches()` (e.g. ".a ~ .b") - By **[@&#8203;karpiuMG](https://github.com/karpiuMG)** in task [#&#8203;1683](capricorn86/happy-dom#1683)

### [`v16.5.3`](https://github.com/capricorn86/happy-dom/releases/tag/v16.5.3)

[Compare Source](capricorn86/happy-dom@v16.5.2...v16.5.3)

##### 👷‍♂️ Patch fixes

-   Fixes problem with encoding and decoding attribute values in HTML - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1678](capricorn86/happy-dom#1678)
-   Fixes issue where it was not possible to query selector by class when the attribute value had line breaks in it - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1678](capricorn86/happy-dom#1678)

### [`v16.5.2`](https://github.com/capricorn86/happy-dom/releases/tag/v16.5.2)

[Compare Source](capricorn86/happy-dom@v16.5.1...v16.5.2)

##### 👷‍♂️ Patch fixes

-   `Event.target` should be the target element after an event has been dispatched - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1529](capricorn86/happy-dom#1529)

### [`v16.5.1`](https://github.com/capricorn86/happy-dom/releases/tag/v16.5.1)

[Compare Source](capricorn86/happy-dom@v16.5.0...v16.5.1)

##### 👷‍♂️ Patch fixes

-   Fixes issue where `Comment`, `Text` and `DocumentFragment` are not instances of their corresponding property on `Window` - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1577](capricorn86/happy-dom#1577)

### [`v16.5.0`](https://github.com/capricorn86/happy-dom/releases/tag/v16.5.0)

[Compare Source](capricorn86/happy-dom@v16.4.3...v16.5.0)

##### 🎨 Features

-   Adds property `GlobalRegistrator.isRegistered` - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1670](capricorn86/happy-dom#1670)

### [`v16.4.3`](https://github.com/capricorn86/happy-dom/releases/tag/v16.4.3)

[Compare Source](capricorn86/happy-dom@v16.4.2...v16.4.3)

##### 👷‍♂️ Patch fixes

-   Adds null check for if browser frame is available in `Response` during tear down of the `Window` - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1669](capricorn86/happy-dom#1669)

### [`v16.4.2`](https://github.com/capricorn86/happy-dom/releases/tag/v16.4.2)

[Compare Source](capricorn86/happy-dom@v16.4.1...v16.4.2)

##### 👷‍♂️ Patch fixes

-   Support using URL as an object for URL:s when using the Browser API - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1664](capricorn86/happy-dom#1664)

### [`v16.4.1`](https://github.com/capricorn86/happy-dom/releases/tag/v16.4.1)

[Compare Source](capricorn86/happy-dom@v16.4.0...v16.4.1)

##### 👷‍♂️ Patch fixes

-   Fixes issue where HTML assigned to `document.documentElement.innerHTML` isnt parsed correctly since v16 - By **[@&#8203;capricorn86](https://github.com/capricorn86)** in task [#&#8203;1663](capricorn86/happy-dom#1663)

### [`v16.4.0`](https://github.com/capricorn86/happy-dom/releases/tag/v16.4.0)

[Compare Source](capricorn86/happy-dom@v16.3.0...v16.4.0)

##### 🎨 Features

-   Allow fetch to be intercepted and modified by sending in an interceptor as a setting - By **[@&#8203;OlaviSau](https://github.com/OlaviSau)** in task [#&#8203;1502](capricorn86/happy-dom#1502)
    -   Read more about this in the Wiki at [IFetchInterceptor](https://github.com/capricorn86/happy-dom/wiki/IFetchInterceptor)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "* 0-3 1 * *" (UTC), Automerge - "* 0-3 * * *" (UTC).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzOS4xMzYuMSIsInVwZGF0ZWRJblZlciI6IjM5LjEzNi4xIiwidGFyZ2V0QnJhbmNoIjoiZm9yZ2VqbyIsImxhYmVscyI6WyJkZXBlbmRlbmN5LXVwZ3JhZGUiLCJ0ZXN0L25vdC1uZWVkZWQiXX0=-->

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6757
Reviewed-by: Earl Warren <[email protected]>
Co-authored-by: Renovate Bot <[email protected]>
Co-committed-by: Renovate Bot <[email protected]>
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