Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
The
unload
event is unreliable on mobile (all browsers) and desktop (safari) where it only fires ~60% of the time.Chrome has stated it's intent to deprecate it: https://developer.chrome.com/docs/web-platform/deprecating-unload and it was previously proposed to mark it as not supported in #20597 - which was correctly closed as too early, and instead a documentation issue was raised to discuss this: mdn/mdn#462.
This PR proposes leaving the support as is (with a note for Chrome), but marking it as deprecated to warn developers more that it should not be relied on.
It should be noted that Safari and Firefox are not quite on board with the path to get there:
However, the MDN documentation page has had a warning at the top of it's page for as long as that repo existed (3 years):
https://developer.mozilla.org/en-US/docs/Web/API/Window/unload_event
So, given it is unrealiable on mobile for all browsers and desktop Safari, that Chrome intends to deprecate it fully, and that we have had a warning at the top of the documentation page for a long time, it seems to me it fits the MDN definition of deprecated:
It has not yet been formally deprecated in the HMTL spec, which might be more problematic for the BCD definition of deprecated which prefers an actual specification update or at least a position.
Discussions in the spec have been ongoing for a while:
whatwg/html#6026
The spec has clarified that the unload handler does not need to run any more when the bfcache can be used - in effect codifying the mobile and Safari unreliability.
TLDR: it's messy but this event really is not recommended to be used (as shown by the warning on MDN already) and that is only likely to increase.
Test results and supporting details
See above
Related issues
Issue to document this deprecation journey: mdn/mdn#462