Discussions » Creation Requests

How to make a site/tab think it's still in focus?

§
Posted: 2021-04-13

Does someone have a code i can use so the site/tab thinks it is still in focus while i go to another site/app?

wOxxOmMod
§
Posted: 2021-04-13
Edited: 2021-04-13

Depending on the site you'll have to spoof the events/properties that it uses. The most common ones are visibilitychange, pagehide, blur so you can start with something like this:

// @run-at document-start
.............
const ael = unsafeWindow.addEventListener;
unsafeWindow.addEventListener = unsafeWindow.document.addEventListener = function(name) {
  if (!/^(visibilitychange|pagehide|blur)$/i.test(name)) {
    return ael.apply(this, arguments);
  }
};

You may need to spoof document.hasFocus() too.

§
Posted: 2021-04-13

sorry, i dont know how to code, what are the parts i need to replace?

Post reply

Sign in to post a reply.