Skip to content
This repository was archived by the owner on Jul 18, 2022. It is now read-only.
This repository was archived by the owner on Jul 18, 2022. It is now read-only.

Why does visibilitychange fire after pagehide in the unload flow? #39

@philipwalton

Description

@philipwalton

The current ordering of pagehide and visibilitychange during a page unload complicates our proposed flow of Lifecycle states for the Lifecycle API.

The reason is the ordering of pagehide and visibilitychange events can be inverted, depending on what the user does. Consider these two examples:

  1. The user loads a page in Tab A and then switches to a new tab B. Later, they close tab A without refocusing it. In this case the ordering of events fired on tab A is visibilitychangepagehide.

  2. The user loads a page in Tab A and then navigates to a new page from a link. In this case the ordering of events fired on tab A is pagehidevisibilitychange.

Wouldn't it make more sense if visibilitychange always fired before pagehide?

Since pagehide is associated with the FROZEN state (for bfcache supporting browsers), and visiblitychange is associated with the HIDDEN state, the current ordering of events suggests that the lifecycle state of a page can transition from ACTIVE to FROZEN to HIDDEN, which doesn't make sense since we only want to freeze hidden tabs.

Does anyone here remember why this ordering was chosen? Would anyone object to changing the ordering in the spec?

https://html.spec.whatwg.org/multipage/browsing-the-web.html#unloading-documents

(Related dicussion WICG/page-lifecycle#7).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions