I have a specific task that needs to be executed for a defined period of time. Currently, I am utilizing the set interval function, but I require a dynamic timeout period fetched from a database. In the getInactiveTimePeriod function, I retrieve the time from browser local storage as a result of an API call. The time is in milliseconds, just as expected. Here is my code:
<script>
var timeInMilliseconds;
window.setInterval(function() {
getInactiveTimePeriod();
} , 10000);
function getInactiveTimePeriod() {
chrome.storage.local.get("user_inactive_time", function (obj) {
var timeInMinuts = obj.user_inactive_time;
timeInMilliseconds = timeInMinuts * 60000;
});
}
getInactiveTimePeriod();
checkUserInactivity();
function checkUserInactivity() {
setTimeout(function () {
// code
}, timeInMilliseconds);
}
checkUserInactivity();
</script>
However, this function only runs once. I need assistance in resolving this issue.