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

Cookies: Fix Goja conversions #1039

Merged
merged 3 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 10 additions & 9 deletions api/browser_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ type BrowserContext interface {
//
// https://datatracker.ietf.org/doc/html/rfc6265.
type Cookie struct {
Name string `json:"name"` // Cookie name.
Value string `json:"value"` // Cookie value.
Domain string `json:"domain"` // Cookie domain.
Path string `json:"path"` // Cookie path.
Expires int64 `json:"expires"` // Cookie expiration date as the number of seconds since the UNIX epoch.
HTTPOnly bool `json:"httpOnly"` // True if cookie is http-only.
Secure bool `json:"secure"` // True if cookie is secure.
SameSite CookieSameSite `json:"sameSite"` // Cookie SameSite type.
URL string `json:"url,omitempty"` // Cookie URL.
Name string `json:"name"` // Cookie name.
Value string `json:"value"` // Cookie value.
Domain string `json:"domain"` // Cookie domain.
Path string `json:"path"` // Cookie path.
ankur22 marked this conversation as resolved.
Show resolved Hide resolved
HTTPOnly bool `js:"httpOnly" json:"httpOnly"` // True if cookie is http-only.
Secure bool `json:"secure"` // True if cookie is secure.
SameSite CookieSameSite `js:"sameSite" json:"sameSite"` // Cookie SameSite type.
URL string `js:"url" json:"url,omitempty"` // Cookie URL.
// Cookie expiration date as the number of seconds since the UNIX epoch.
Expires int64 `json:"expires"`
}

// CookieSameSite represents the cookie's 'SameSite' status.
Expand Down
9 changes: 8 additions & 1 deletion examples/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export default async function () {
sameSite: 'Strict',
domain: '127.0.0.1',
path: '/',
httpOnly: true,
secure: true,
},
// this cookie expires in a day
{
Expand Down Expand Up @@ -67,6 +69,12 @@ export default async function () {
check(cookies[0], {
'cookie 1 name should be testcookie': c => c.name === 'testcookie',
'cookie 1 value should be 1': c => c.value === '1',
'cookie 1 should be session cookie': c => c.expires === -1,
'cookie 1 should have domain': c => c.domain === '127.0.0.1',
'cookie 1 should have path': c => c.path === '/',
'cookie 1 should have sameSite': c => c.sameSite == 'Strict',
'cookie 1 should be httpOnly': c => c.httpOnly === true,
'cookie 1 should be secure': c => c.secure === true,
});
check(cookies[1], {
'cookie 2 name should be testcookie2': c => c.name === 'testcookie2',
Expand Down Expand Up @@ -94,7 +102,6 @@ export default async function () {
url: 'https://baz.com'
}
]);

cookies = context.cookies('http://foo.com', 'https://baz.com');
check(cookies.length, {
'number of filtered cookies should be 2': n => n === 2,
Expand Down