brian-girko / always-active

Pretend a webpage is in its active state even if not
https://webextension.org/listing/always-active.html
75 stars 12 forks source link

Method to Detect Always-Active #21

Closed landoncrabtree closed 1 year ago

landoncrabtree commented 2 years ago
        var i = 0;
        var blur = false;

        window.onfocus = function (ev) {
            if (i > 0 && !blur) {
                console.log("onFocus() but never called onBlur()")
            } else {
                i++;
                console.log("onFocus: tab is active");
            }
        };

        window.onblur = function (ev) {
            blur = true;
            console.log("onBlur: tab is inactive");
        };

This Javascript can detect Always-Active. If onFocus is called, but onBlur was not, then wouldn't that imply something fishy is going on and that the user did indeed lose focus of the window?

ghost commented 2 years ago

I mentioned this here https://github.com/brian-girko/always-active/issues/18#issuecomment-1073210131

brian-girko commented 1 year ago

Closing as fixed.