-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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 #314
Cookies #314
Conversation
docs/api.md
Outdated
If URLs are specified, only cookies for those URLs are returned. | ||
|
||
#### page.deleteCookie(...cookies) | ||
- `...cookies` <[Object]> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here and below: <[Array]<[Object]>>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like putting array when we have a spread operator. The user doesn't pass in an array.
An update to the cookie protocol is landing in r495262 https://chromium-review.googlesource.com/c/617750 |
docs/api.md
Outdated
- `secure` <[boolean]> | ||
- `sameSite` <[string]> `"Strict"` or `"Lax"`. | ||
|
||
If no URLs are specified, this method returns cookies related to the current page. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you should inherit this poor DTP semantics. There is no real 'related to the page', there are cookies matching domains, paths and names. I would suggest to add optional name, domain and path parameters that would match the cookies. Your underlying implementation would be fetching everything using Network.getAllCookies
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd agree if the method was browser.setCookie. But page.setCookie should act like I set a cookie for the page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you know what Network.getCookies
without urls
does...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok now I don't think I do either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to be able to do
page.setCookie({name, value});
page.deleteCookie({name, value});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Disregard that, I read this comment as being on setCookie.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I think your understanding of 'related to the page' is different from the protocol one. I'm fine with your understanding, but it needs to be clarified and implementation needs to be changed. Also, you might want to pull this into the frame and alias in page)
#### page.deleteCookie(...cookies) | ||
- `...cookies` <...[Object]> | ||
- `name` <[string]> **required** | ||
- `url` <[string]> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either url or domain should be required for scoping. Also, this method will delete multiple cookies for each pattern, so might be worth calling method deleteCookies
and parameters patterns
- `...cookies` <...[Object]> | ||
- `name` <[string]> **required** | ||
- `value` <[string]> **required** | ||
- `url` <[string]> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
either url or domain required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It uses the page url if none is specified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cookies are not associated with the page, they are associated with the document (frame).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm super excited for this feature!
0d27e1c
to
350e0ff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm % nits
lib/Page.js
Outdated
*/ | ||
async deleteCookie(...cookies) { | ||
for (const cookie of cookies) { | ||
const item = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const item = Object.assign({}, cookie);
test/test.js
Outdated
value: '3' | ||
}); | ||
expect(await page.evaluate('document.cookie')).toBe('cookie1=1; cookie2=2; cookie3=3'); | ||
page.deleteCookie({name: 'cookie2'}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
technically, you'd want to await
it here
lib/Page.js
Outdated
for (const cookie of cookies) { | ||
const item = {}; | ||
Object.assign(item, cookie); | ||
const pageURL = this.url(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: bring pageURL out of the loop
Closes #53