-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Page Visibility API #525
Comments
seems like a great idea to me could be a simple as adding a special case for Line 292 in c7bde5a
are you interested in making this change? I can show you how to write tests, etc. for it... |
I just added syntax for filtering polls: And it looks like the https://developer.mozilla.org/en-US/docs/Web/API/Document/hidden With that, can I close this? |
That doesn't quite allow making a request as soon as the tab gains focus, which would be useful for infrequently polled items. Maybe the best solution is a little JS to fire custom events? |
OK, I set it up so you can listen |
I can confirm this is working now in 1.5.0, with the syntax: |
This this should be added as a example in the docs, isn'it ? EDIT: In the end i make this:
See: #821 But i think it's should be easier to setup this, isn't it? Think i will open a new issues for this. EDIT2: #824 |
I wanted to create an element that fetches whenever the tab comes into focus, as detectable with the page visibility API. I tried:
but this did not seem to work, since
document
is not a valid CSS selector.Supporting
from:document
or similar might be all that's needed to support this API, but it strikes me as something that htmx could abstract a little.It could be useful to have virtual events for "tab became visible" and "tab became hidden". Then the repetitive filter
[visibilityState === 'visible']
could be avoided, and the events could work whenallowEval
isfalse
.Also there could be event modifiers for tab visible / tab hidden, so we could specify "poll only while the tab is visible". Polling only while visible would even make a sensible default...
The text was updated successfully, but these errors were encountered: