tantangula
tantangula

Reputation: 314

chrome.idle.onStateChanged not triggering function

I am building a note taking app for Chrome and I want the app to save its progress when the user stops typing, but I can't get chrome.idle to trigger a state change

chrome.idle.setDetectionInterval(10);

chrome.idle.onStateChanged.addListener(
    function (newState) {
        var messageElement = document.querySelector("#message");
        messageElement.innerHTML = "idle";
        if (newState === "idle")
            save();
    }
);

Chrome requires a permission to access the idle functionality so I have included the idle permission in the manifest. However, when I load the app with the extensions tool and view the permissions, it says I have no special permissions. Could this have anything to do with why the idle state change isn't triggering my function?

Upvotes: 2

Views: 2367

Answers (1)

tantangula
tantangula

Reputation: 314

In case anyone else runs into this, the issue is that the minimum value setDetectionInterval will accept is 15. I found some code that is trying to do exactly what I am doing in a Safari Online book...

chrome.idle.setDetectionInterval(15);

chrome.idle.onStateChanged.addListener(
    function (state) {
        if (state === "idle" && dirty)
            save();
    }
);

This code is almost exactly the same, but this version works and mine didn't. The console prints an error that says the minimum value for the interval is 15 seconds where I was trying to check every 10. So I switched my code to check every 15 seconds and everything worked

Upvotes: 3

Related Questions