rubycdp / ferrum

Headless Chrome Ruby API
https://ferrum.rubycdp.com
MIT License
1.69k stars 120 forks source link

`browser.page.cookies` does not return cookies only used by that page #368

Open postmodern opened 1 year ago

postmodern commented 1 year ago

I feel like browser.cookies should return all cookies, while browser.page.cookies should only return cookies for the page, based on the current page's path and domain.

route commented 1 year ago

@postmodern could you show an example where it's useful?

postmodern commented 1 year ago

@route I want to dump out the cookies used by the current page to a file, so I can load the cookies into other tools or back into a new Ferrum::Browser instance. I noticed that both browser.cookies and browser.page.cookies returns cookies for the current website domain, and all previous websites that the browser instance has visited. I suppose I could add my own method which filters browser.cookies by comparing Cookie#domain against URI(browser.url).host.

route commented 1 year ago

Since browser.cookies is just a convenient alias to browser.page.cookies with default page, this behavior looks ok to me. Though I'm a bit surprised that Network.getAllCookies returns all cookies even for previously visited websites but thinking a bit more about it and this is also appears to be correct behavior from Chrome's perspective because context stays the same. Like you said you can just filter out unneeded cookies by domain.

postmodern commented 1 year ago

Maybe in ferrum 1.0.0 you could rename cookies to cookie_jar which would imply all cookies, and have a cookies method that only returned the cookies used by the current page.