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 #314

Merged
merged 7 commits into from
Aug 24, 2017
Merged

Cookies #314

merged 7 commits into from
Aug 24, 2017

Conversation

JoelEinbinder
Copy link
Contributor

Closes #53

docs/api.md Outdated
If URLs are specified, only cookies for those URLs are returned.

#### page.deleteCookie(...cookies)
- `...cookies` <[Object]>
Copy link
Contributor

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]>>

Copy link
Contributor Author

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.

@JoelEinbinder
Copy link
Contributor Author

JoelEinbinder commented Aug 17, 2017

An update to the cookie protocol is landing in r495262

https://chromium-review.googlesource.com/c/617750
also https://chromium-review.googlesource.com/c/614721 landed recently.

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.
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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...

Copy link
Contributor Author

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.

Copy link
Contributor Author

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});

Copy link
Contributor Author

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.

Copy link
Contributor

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]>
Copy link
Contributor

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]>
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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).

Copy link

@MiniCodeMonkey MiniCodeMonkey left a 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!

@JoelEinbinder JoelEinbinder force-pushed the cookies branch 3 times, most recently from 0d27e1c to 350e0ff Compare August 23, 2017 23:33
Copy link
Contributor

@aslushnikov aslushnikov left a 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 = {};
Copy link
Contributor

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'});
Copy link
Contributor

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();
Copy link
Contributor

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

@aslushnikov aslushnikov merged commit 0791774 into puppeteer:master Aug 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants