Idle time detection

Hi , I’ve developed an application which contain a login form (Authentication and Authorization ). This application is used to handles secure data in my organization.
As per the organization policies - I need to detect idle time situation and run logout.

I plan on a count-down timer that will do a logout when the idle time had passed.
To make this work, I need to be able capture any mouse event on the screen (to reset the count-down timer).

Any idea how to capture such event (can I add js::AddEventListener to solve this )

Raz

Hey @razgil, it might be possible to do this by using st.html and add an event listener like

st.html("""
<script>
window.addEventListener(...)
</script>
""")

I believe that events should continue to be caught by other listeners as well unless configured otherwise, but I have not tested this out.

10x

Will check

Raz

Sadly is seems that st.html can not run the java script.
And st.components.v1.html runs in an isolated iframe so we cannot get the response (i.e. mouse moved).
The only option I see is to build a new streamlit custom component that can capture and report events

Oh yeah, you are right. The thing with custom components is that they also run in their own iframes, so it sounds like you would run into the same limitation as with st.components.v1.html, right? Btw. here is a GitHub issue about the possibility to run components outside of an iFrame you could upvote: Inject Streamlit Components Directly into html instead of iFrame · Issue #2262 · streamlit/streamlit · GitHub (even though it does not help right in this moment).

The only alternatives I can think of right now are to somehow fiddle with the Streamlit library’s index.html and inject the script there, either by patching the local file or by having a proxy in front of it to do it on the fly.

as far as checked (and I’m not a UI expert) there is a command that sends information to the parent streamlit container from an embedded js script :

js_code =“”“… Streamlit.setComponentValue(result); …”“”

in streamlit we can pick the value with :

result = components.html(js_code, height=0,width=0)

Problem is I found that I need a ST custom component for this approach.
Maybe I’m missing something here .

Oh and then you want to trigger the logout from the backend side? yeah that should work depending on how your logout works :+1: I mentally was on client-side tracking / logging out (e.g. by automatically clicking on a logout button or so)