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

Character.ai detects inactive tabs #32

Open omnicron-llc opened 1 year ago

omnicron-llc commented 1 year ago

I believe you can test this without signing up - but creating an account is free. The animations during AI chat will pause when the window is not active, so they are using a mechanism this extension doesn't handle.

brian-girko commented 1 year ago

It appears that on this page, the combination of "ResizeObserver" and "requestAnimationFrame" is used for rendering. While we do modify "requestAnimationFrame," the browser doesn't refresh the DOM's visual updates when the tab is hidden. As a result, the "ResizeObserver" function isn't triggered.

I'm not sure how we can bypass this

Fukitsu commented 1 year ago

This userscript works on Firefox but not Chromium. I've tried all kind of things on Chromium but I just can't get it to work

(function() {
    'use strict';

    // Override the visibilityState property of the document to always return "visible"
    Object.defineProperty(document, "visibilityState", {value: "visible", writable: false});

    // Override the hidden property of the document to always return false
    Object.defineProperty(document, "hidden", {value: false, writable: false});

    // Override the addEventListener method of the document to prevent visibilitychange events from being registered
    const originalAddEventListener = document.addEventListener;
    document.addEventListener = function(type, listener, options) {
        if (type !== "visibilitychange") {
            originalAddEventListener.call(document, type, listener, options);
        }
    };
})();