Order of OnCookiesAccessed() callbacks

0 views
Skip to first unread message

Ryan Tarpine

unread,
Jun 12, 2024, 1:03:42 PMJun 12
to stora...@chromium.org
Hello fellow storage users,

I've long had the mental model that the WebContentsObserver::OnCookiesAccessed() callback was called in basically the same order that actual cookie reads and writes happened (at least for a single primary main frame).

But lately I was investigating some test flakiness and I was surprised what I saw:

(1) Some cookie reads were reported before the writes that set the value. 

For example: I visit http://b.test/empty.html and execute "document.cookie = 'bounce=true';".
In my logs, I sometimes see that OnCookiesAccessed() was called for a read by http://b.test/favicon.ico before it was called for the write by http://b.test/empty.html

(2) Some cookie accesses are reported for pages visited later before ones visited earlier

For example: I visit http://b.test/empty.html, execute "document.cookie = 'bounce=true';", then navigate (by assigning window.location and waiting for the navigation to complete) to http://c.test/empty.html, and finally execute "document.cookie = 'final=yes';" on that page.

I sometimes see the c.test/favicon.ico cookie read before the b.test/empty.html cookie write

Interestingly, both unexpected cases involve the favicon request. (Is that a coincidence or not?)

Is this type of ordering expected?

If so, is there any other way to be notified for cookie accesses that would ensure ordering, and be attributed to the URLs that performed them? For example, I see the CookieManager mojo interface has an AddGlobalChangeListener(), but (1) it's only for changes; and (2) it doesn't include the URL. I think we could adapt to (1), but not (2).

Our code is currently in //chrome but is in the process of moving to //content. Will being in //content (and seeing all the Impls instead of just the public API) make this any easier?

Thanks,
Ryan
Reply all
Reply to author
Forward
0 new messages