Skip to content

feat(cookies): add context.cookies and scope page.cookies to the page - #690

Merged
route merged 1 commit into
mainfrom
feat/context-cookies
Nov 1, 2026
Merged

route merged 1 commit into
mainfrom
feat/context-cookies

Conversation

@route

@route route commented Nov 1, 2026

Copy link
Copy Markdown
Member

Cookies belong to a browser context, every page in it shares them. This puts them there and drops the deprecated Network.getAllCookies.

Changes

  • context.cookies (new): every cookie in the context whatever its domain, via Storage.getCookies/setCookies/clearCookies. Has each, all, [], set, remove, clear, store, load. Storage has no delete, so remove expires the matching cookies.
  • browser.cookies is the default context's cookies instead of the page's. Same results as before.
  • page.cookies (Page::Cookies) is what the page sees: cookies sent to its URL and its frames' URLs (Network.getCookies), or each(urls:). set/remove default to the page's host, clear keeps other domains, no store/load.
  • cookies[name, domain:, path:] picks one of the cookies sharing a name.
  • cookies.all is deprecated, keyed by name it kept one of the cookies sharing a name. Use to_a, or map(&:name).

Breaking (0.21)

  • page.cookies.each/all/[] return only the page's cookies, nothing before the first go_to. Use browser.cookies or browser.contexts[page.context_id].cookies for all of them.
  • page.cookies.clear keeps other domains, page.cookies.store/load are gone.
  • page.cookies.set/remove default to the page's host rather than the :base_url host.
  • page.cookies is a Ferrum::Page::Cookies, Ferrum::Cookies.new takes (client, context_id).
  • browser.cookies.set returns true and raises BrowserError for an invalid cookie, as Network.setCookie did, with a vaguer message.

Cuprite and code using browser.cookies see no change apart from the all warning.

Tests

spec/cookies_spec.rb (context scope, contexts kept apart, remove(url:), [] filters, all deprecation) and the new spec/page/cookies_spec.rb.

Cookies belong to the context. context.cookies uses Storage.getCookies/setCookies/clearCookies instead of the
deprecated Network.getAllCookies, and browser.cookies is the default context's. page.cookies returns only the
cookies sent to the page's URL and its frames' (Network.getCookies), set/remove default to the page's host,
clear keeps other domains, store/load stay on the context.

all keys cookies by name, so of the cookies sharing a name only one survived. It is deprecated, to_a and
map(&:name) cover it. [] takes domain: and path: to pick one of them.
@route
route merged commit fbcca33 into main Nov 1, 2026
7 checks passed
@route
route deleted the feat/context-cookies branch November 1, 2026 10:30
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.

1 participant