Session timeout countdown using Webworkers vs setTimeout or setInterval

I want to detect a users inactivity and kill the session.So far I’ve been using setTimeout,setInterval,and using a timestamp which has failed. I want to impliment it in **webworkers ** and still use setTimeout or setInterval and I’m hoping that the countdown will be accurate? Is there otherways to impliment this or are webworkers the way to go and will it be reliable?

I just want to accurately call a function on a set countdown or an interval.