Kartik Soneji
Kartik Soneji

Reputation: 1246

How to force a webpage to think that it is in or out focus?

I am trying to build a web app (to learn about WebSockets and adaptive behavior) that polls different social media sites and shows all the latest updates in one place. I want to make the page stop updating while out of focus, and then update again when in focus.

Testing the out of focus behavior has been very difficult, since I have to rely on logs to ensure that my app is working properly, and cannot have the window open in one monitor and work on the code in another monitor.

My question is:
Is there a way to "force" the tab to think that it is in or out of focus, like force element state in DevTools, but for the entire tab.

I am running Chrome on Windows 10. I could not find a way to do this using DevTools, and do not want to setup a whole testing framework just for such a simple thing.

Thank you for your time.

Upvotes: 1

Views: 8735

Answers (1)

Kayce Basques
Kayce Basques

Reputation: 25957

  1. Open the Command Menu.
  2. Run the Emulate a focused page command.

If you create a Live Expression and set the expression to document.hasFocus() you'll see that the page always thinks it's in focus after you run the Emulate a focused page command.

Upvotes: 9

Related Questions