FR: Observer for Page's LifecycleState? PageLifecycleObserver?

81 views
Skip to first unread message

Daniel Murphy

unread,
Dec 8, 2025, 7:20:57 PM (4 days ago) Dec 8
to Chromium-dev
Do we have anything like this? It would be super useful for me to decouple code from the WebContents - as I want to cancel operations when a page goes to kPendingDeletion, and pause it if it goes to kInBackForwardCache.

Dan

Daniel Murphy

unread,
Dec 9, 2025, 12:47:38 PM (3 days ago) Dec 9
to Chromium-dev

There is an observer for this on WebContentsObserver - but we shouldn't need a whole webcontents - we should be able to just observe this on a page.

Sidhin Thomas

unread,
Dec 9, 2025, 1:01:40 PM (3 days ago) Dec 9
to dmu...@chromium.org, Chromium-dev
I have a maybe dumb question, isn't Page == Webcontents in context of the browser? 

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CA%2B4qT30hDh5gbgQm%3DntnOPj8LJsYL4E6CEnqZ3uFYpL%2B7%2BU%2BZw%40mail.gmail.com.

Daniel Murphy

unread,
Dec 9, 2025, 1:06:21 PM (3 days ago) Dec 9
to Sidhin Thomas, Chromium-dev
Good question. Yes and no. A web contents can be navigated. A page cannot*.

Web contents will have the 'primary page changed' for each navigation. That is the recommended way to listen for navigations for primary frame in the WebContentsObserver now.

There is a SUPER common pattern (we use it all over the place in PWA code) where someone wants to calculate something on a WebContents, and the basically send the results of that to something else to do something with it (or just store it for reference). But then, it implements all of the navigation listening code to 'clear' that value and recalculate it on the next navigation complete. Even more - it'll often listen to WebContentsDestroyed with is a classic source of bugs (and a presubmit compliains about that).

Instead, you can make a PageUserData to store something on a page object itself. This is super great, as it's compatible with BFCache and prerendering (if you want it to be). Any calculations are saved etc. Destruction of the page removes the data. hooray! However - there isn't a way for a PageUserData to listen to its own lifecycle in a simple way. We have code that executes after a page becomes active, and then I want to 'stop' if it enters bfcache.


Daniel Murphy

unread,
Dec 9, 2025, 1:06:43 PM (3 days ago) Dec 9
to Sidhin Thomas, content-owners, Chromium-dev
As per suggestion by dcheng, +content-owners to see if anyone is thinking about stuff like this.

Fergal Daly

unread,
Dec 10, 2025, 1:41:15 AM (2 days ago) Dec 10
to dmu...@chromium.org, Sidhin Thomas, content-owners, Chromium-dev
On Wed, 10 Dec 2025 at 02:53, Daniel Murphy <dmu...@chromium.org> wrote:
As per suggestion by dcheng, +content-owners to see if anyone is thinking about stuff like this.

I recently added WebContentsBasedCanceller to try to simplify some of what you are talking about. It does not handle resuming something on `pageshow` but I suppose it could.

However it doesn't address your complaint of not need WebContents,

F

 

Daniel Murphy

unread,
Dec 10, 2025, 12:39:33 PM (2 days ago) Dec 10
to Fergal Daly, Sidhin Thomas, content-owners, Chromium-dev
I might take a stab at it. In the PWA code, this simplifies a bunch of stuff, and I imagine MANY systems do this:

- Listen for navigation to complete (page to be changed)
- "calculate stuff and save it", "possibly call observers", "call into other areas of code"
- Listen for navigation to start / complete again to clear state and start again

This is incompatible inherently with things like bfcache (and we re-calculate stuff as a result) and cannot easily take advantage of prerendering if it wants to.

For storage, things like a PageUserData allow for storage in an inherently bf-cache compatible way. You COULD store than, and then in the 'navigation complete' check the existing page to see what the state it, and use cached state if it's there.

But wouldn't it be nice to just not have to deal with WebContents at all? Just have a PageUserData that can also listen for lifecycle events on the page itself?

I'll start poking at this if I have time.

Daniel Murphy

unread,
Dec 11, 2025, 3:05:39 PM (21 hours ago) Dec 11
to content-owners, Daniel Murphy, Sidhin Thomas, content-owners, Chromium-dev, Fergal Daly, Devlin Cronin
Idea from +Devlin - since a Page cannot be owned by more than one WebContents (each page has one web contents ), it's not TOO hard to have a WebContentsUserData manage these observers, as it can listen to that event on the WebContentsObserver, and dispatch events..

But - to check - it's true now and into the future that a page has one web contents, and a web contents has many pages?
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+unsubscribe@chromium.org.

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+unsubscribe@chromium.org.
Reply all
Reply to author
Forward
0 new messages