Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Fix issue #238, use pagehide not unload listener #250

Merged
merged 1 commit into from
Apr 22, 2022

Conversation

rhelmer
Copy link
Contributor

@rhelmer rhelmer commented Apr 21, 2022

This seems to work fine in Firefox and (mostly) in Chrome, but it intermittently fails to fire in Chrome.

Per MDN, the visibilitychange event is preferred, but it does note the back/forward cache behavior. Using pagehide when that isn't available is suggested as well.

I think the root cause might be that the back/forward cache doesn't get canceled in Chrome the way it does in Firefox, but I'm having a lot of trouble reproducing it in a test environment. Using pagehide instead seems to work when I test sites in the wild, and it still passes the test suite.

@rhelmer rhelmer self-assigned this Apr 21, 2022
@rhelmer
Copy link
Contributor Author

rhelmer commented Apr 21, 2022

Hm, on further testing I don't Chrome supports document.visibilityState === 'unloaded' and document.visibilityState === 'hidden' isn't quite what we want, but I'll see what I can determine.

See issue #238 for more.

@rhelmer rhelmer force-pushed the use-visibility-hidden-not-unload branch from d8d00dc to ff30444 Compare April 21, 2022 18:32
@rhelmer rhelmer changed the title Fix issue #238, use visibilitychange not unload listener Fix issue #238, use pagehide not unload listener Apr 21, 2022
@rhelmer rhelmer requested a review from aaga April 21, 2022 20:02
Copy link

@aaga aaga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confirmed test passes locally for me as well.

@rhelmer just want to check my understanding from reading the linked issue: the plan is to eventually use tabs.onChange, but we're doing it this way for now for MVP?

@rhelmer
Copy link
Contributor Author

rhelmer commented Apr 22, 2022

confirmed test passes locally for me as well.

@rhelmer just want to check my understanding from reading the linked issue: the plan is to eventually use tabs.onChange, but we're doing it this way for now for MVP?

Yes, I think ultimately depending on the content script environment is going to mean depending on implementation details and we won't get predictable cross-browser behavior there anytime soon. The tabs.* APIs on the other hand are more amenable to standardizing.

@rhelmer rhelmer merged commit 4d2357b into main Apr 22, 2022
@rhelmer rhelmer deleted the use-visibility-hidden-not-unload branch April 22, 2022 17:15
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants