WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
151234
visibilitychange:hidden doesn't fire during page navigations
https://bugs.webkit.org/show_bug.cgi?id=151234
Summary
visibilitychange:hidden doesn't fire during page navigations
Ojan Vafai
Reported
2015-11-12 16:39:25 PST
visibility state should transition to hidden whenever a page might go away. Unlike unload/pagehide, we can fire these reliably. See
https://github.com/w3c/page-visibility/issues/18
for more details, particularly, igrigorik's table near the top that shows where browser's don't fire this. The Firefox behavior of having green for all of the visibility-change-->hidden column is the one that matches the spec and makes for the best developer platform. Ryosuke, are you the right person on WebKit to talk to about this?
Attachments
Patch
(41.07 KB, patch)
2020-09-25 10:15 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(42.36 KB, patch)
2020-09-25 10:47 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(40.10 KB, patch)
2020-09-25 12:02 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(40.06 KB, patch)
2020-09-25 12:07 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(46.30 KB, patch)
2020-09-25 15:47 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(46.41 KB, patch)
2020-09-25 16:37 PDT
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Show Obsolete
(5)
View All
Add attachment
proposed patch, testcase, etc.
Ilya Grigorik
Comment 1
2015-11-12 16:54:20 PST
FWIW, test page:
http://output.jsbin.com/zubiyid/latest/quiet
- load it, unload the page and visit it again.
Ilya Grigorik
Comment 2
2015-11-25 13:08:22 PST
Related issue
https://bugs.webkit.org/show_bug.cgi?id=151610
, and some additional context:
https://www.igvita.com/2015/11/20/dont-lose-user-and-app-state-use-page-visibility/
Radar WebKit Bug Importer
Comment 3
2015-11-30 09:01:03 PST
<
rdar://problem/23688763
>
Lucas Forschler
Comment 4
2019-02-06 09:18:44 PST
Mass move bugs into the DOM component.
Daniel
Comment 5
2019-06-21 14:06:39 PDT
This is a duplicate of issue #116769.
sideshowbarker
Comment 6
2020-09-24 22:19:37 PDT
Please see
https://bugs.webkit.org/show_bug.cgi?id=116769#c7
for some details about where (back in 2013…) this issue was discussed, and the HTML spec change that was made in relation to it. I hope we can get this resolved — because among other possible consequences, I take it that this may be preventing web developers from being able to use document.sendBeacon() in the way it’s intended to be used.
Ryosuke Niwa
Comment 7
2020-09-24 22:26:49 PDT
FWIW, pagehide event is still fired so that would be the workaround for now. We should really fix this bug though...
sideshowbarker
Comment 8
2020-09-24 22:59:34 PDT
(In reply to Ryosuke Niwa from
comment #7
)
> FWIW, pagehide event is still fired so that would be the workaround for now. > We should really fix this bug though...
Hi Ryosuke — thanks much for the response. Yeah, I have gleaned that using the pagehide event is the workaround — and I’m actually working on documenting things that way in MDN and the browser-compat-data repo (BCD), which is sort of how I ended up here. So yeah I guess what I’m hoping for is that we get this resolved such that we don’t need to have MDN and BCD forever essentially telling developers, “You can rely on the visibilitychange event interoperably firing as expected in every current browser except Safari — for which you’ll also need to write extra special-case code to additionally check the pagehide event.”
Ryosuke Niwa
Comment 9
2020-09-24 23:38:01 PDT
FWIW, this is probably one of the easiest bugs to fix! I'd mention it in getting-started on webkit's slack and see if anyone finds it interesting enough to fix it.
sideshowbarker
Comment 10
2020-09-25 02:31:38 PDT
FYI
https://github.com/mdn/browser-compat-data/pull/6763
is a pull request I raised today to update the MDN Browser Compatibility data (tables in MDN) to give a clear indication web developers about this issue.
Chris Dumez
Comment 11
2020-09-25 10:15:11 PDT
Created
attachment 409705
[details]
Patch
Chris Dumez
Comment 12
2020-09-25 10:47:24 PDT
Created
attachment 409708
[details]
Patch
Ryosuke Niwa
Comment 13
2020-09-25 11:50:04 PDT
Comment on
attachment 409708
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=409708&action=review
> Source/WebCore/dom/Document.h:487 > + void setVisibilityStateOverride(Optional<VisibilityState> visibilityState) { m_visibilityStateOverride = visibilityState; }
Since we don't need a generic override mechanism, I'd prefer having a boolean state and call this something like setIsUnloaded.
> Source/WebCore/loader/FrameLoader.cpp:3280 > + m_frame.document()->dispatchEvent(Event::create(eventNames().visibilitychangeEvent, Event::CanBubble::Yes, Event::IsCancelable::No));
We can't always fire event here. We should put this inside unloadEvebtPolicy check below.
Darin Adler
Comment 14
2020-09-25 11:52:13 PDT
Comment on
attachment 409708
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=409708&action=review
> Source/WebCore/loader/FrameLoader.cpp:3278 > + // Dispatch visibilitychange event.
I don’t think we need this comment, because the code says dispatchEvent, visibilitychangeEvent. If we want to make that more readable I suggest helper functions to get rid of some of the distracting additional items. On the other hand I think it would be worthwhile to comment about why we are overriding the visibility state. That doesn't seem obvious to me. Possible topics would be why we need to override it now, why we didn’t do it earlier, and why it’s OK to leave it that way permanently.
Chris Dumez
Comment 15
2020-09-25 11:54:47 PDT
Comment on
attachment 409708
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=409708&action=review
>> Source/WebCore/loader/FrameLoader.cpp:3278 >> + // Dispatch visibilitychange event. > > I don’t think we need this comment, because the code says dispatchEvent, visibilitychangeEvent. If we want to make that more readable I suggest helper functions to get rid of some of the distracting additional items. > > On the other hand I think it would be worthwhile to comment about why we are overriding the visibility state. That doesn't seem obvious to me. Possible topics would be why we need to override it now, why we didn’t do it earlier, and why it’s OK to leave it that way permanently.
Once a document is unloaded, there is no going back. I will replace with a isUnloaded boolean as Ryosuke suggested.
>> Source/WebCore/loader/FrameLoader.cpp:3280 >> + m_frame.document()->dispatchEvent(Event::create(eventNames().visibilitychangeEvent, Event::CanBubble::Yes, Event::IsCancelable::No)); > > We can't always fire event here. We should put this inside unloadEvebtPolicy check below.
In this scope, the unload event will be fired no matter what so I think we need to fire the visibilitychange event also unconditionally here too. unloadEventPolicy controls whether or not to fire the pagehide event here.
Darin Adler
Comment 16
2020-09-25 12:00:48 PDT
(In reply to Chris Dumez from
comment #15
)
> Once a document is unloaded, there is no going back.
Yes, I understood that. My point is that someone in the future might not, which is why I suggested a comment.
Chris Dumez
Comment 17
2020-09-25 12:02:07 PDT
Created
attachment 409715
[details]
Patch
Chris Dumez
Comment 18
2020-09-25 12:02:45 PDT
(In reply to Darin Adler from
comment #16
)
> (In reply to Chris Dumez from
comment #15
) > > Once a document is unloaded, there is no going back. > > Yes, I understood that. My point is that someone in the future might not, > which is why I suggested a comment.
I don't think a comment is still needed after applying Ryosuke's suggestion (see latest patch iteration) but please let me know if you disagree.
Chris Dumez
Comment 19
2020-09-25 12:07:42 PDT
Created
attachment 409717
[details]
Patch
Darin Adler
Comment 20
2020-09-25 12:15:09 PDT
(In reply to Chris Dumez from
comment #18
)
> I don't think a comment is still needed after applying Ryosuke's suggestion > (see latest patch iteration) but please let me know if you disagree.
Sure, looks fine.
EWS
Comment 21
2020-09-25 13:11:53 PDT
Committed
r267589
: <
https://trac.webkit.org/changeset/267589
> All reviewed patches have been landed. Closing bug and clearing flags on
attachment 409717
[details]
.
Simon Fraser (smfr)
Comment 22
2020-09-25 13:17:47 PDT
Does this resolve
bug 116770
?
Chris Dumez
Comment 23
2020-09-25 14:29:52 PDT
Reverted
r267589
for reason: Broke document.visibilityState when coming out of back/forward cache Committed
r267593
: <
https://trac.webkit.org/changeset/267593
>
Chris Dumez
Comment 24
2020-09-25 14:32:02 PDT
(In reply to Simon Fraser (smfr) from
comment #22
)
> Does this resolve
bug 116770
?
I will but I had a bug. I am reworking the patch.
Chris Dumez
Comment 25
2020-09-25 15:47:36 PDT
Created
attachment 409751
[details]
Patch
Chris Dumez
Comment 26
2020-09-25 15:50:08 PDT
(In reply to Chris Dumez from
comment #24
)
> (In reply to Simon Fraser (smfr) from
comment #22
) > > Does this resolve
bug 116770
? > > I will but I had a bug. I am reworking the patch.
This new iteration now correctly deals with the back/forward cache and we now match Firefox's behavior in this regard.
Ryosuke Niwa
Comment 27
2020-09-25 16:33:40 PDT
Comment on
attachment 409751
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=409751&action=review
> Source/WebCore/loader/FrameLoader.cpp:3284 > + m_frame.document()->setHiddenDueToDismissal(true);
This is confusing name. How about setVisibilityHiddenDueToPageDismissal?
Chris Dumez
Comment 28
2020-09-25 16:34:43 PDT
(In reply to Ryosuke Niwa from
comment #27
)
> Comment on
attachment 409751
[details]
> Patch > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=409751&action=review
> > > Source/WebCore/loader/FrameLoader.cpp:3284 > > + m_frame.document()->setHiddenDueToDismissal(true); > > This is confusing name. How about setVisibilityHiddenDueToPageDismissal?
Yes, I had trouble finding a good name. I will go with your suggestion unless someone has a better idea.
Chris Dumez
Comment 29
2020-09-25 16:37:05 PDT
Created
attachment 409760
[details]
Patch
EWS
Comment 30
2020-09-25 17:50:05 PDT
Committed
r267614
: <
https://trac.webkit.org/changeset/267614
> All reviewed patches have been landed. Closing bug and clearing flags on
attachment 409760
[details]
.
Chris Dumez
Comment 31
2020-09-25 17:54:43 PDT
***
Bug 116769
has been marked as a duplicate of this bug. ***
Chris Dumez
Comment 32
2020-09-25 17:54:58 PDT
***
Bug 116770
has been marked as a duplicate of this bug. ***
Sam Sneddon [:gsnedders]
Comment 33
2022-07-05 14:11:51 PDT
***
Bug 194897
has been marked as a duplicate of this bug. ***
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug