1

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.

4
  • Welcome to SuperUser. Voting to move to StackOverflow, a programmer-oriented website. You can see some other StackExchange sites at stackexchange.com/sites Commented May 24, 2019 at 20:29
  • You might consider creating a VM, opening the VM's browser to your site, leaving the VM cursor on your site, then switching back to your main PC with a keyboard command. Or visiting the site on another nearby physical machine. Commented May 24, 2019 at 20:30
  • @ChristopherHostage That seems a little overkill. Commented May 25, 2019 at 7:51
  • If you have access to multiple PCs, the simplest answer is to visit the site from PC 2 and leave the tab in focus. If you only have 1 PC, then you can make do with a VM. Given that Keyboard + Mouse browsers only have 1 focus, and you need the focus for other actions on your development PC, I don't know of another way to do it. Commented May 26, 2019 at 18:20

1 Answer 1

9
  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.

6
  • Thank you for the answer, but is there a way to force a page to be out of focus, even if it is in focus? @Kayce Commented May 26, 2019 at 17:06
  • I can’t picture how that’s supposed to work. The page is out of focus even though you’re interacting with it? That sounds like a logical contradiction to me. If you provide a step-by-step example that should clear up any misunderstanding. Commented May 26, 2019 at 17:20
  • I envisioned something that allows me to inspect elements (using the element) picker without causing the page to momentarily be in focus. I understand if that is not possible, and the only solution that I have found is to use breakpoints and "freeze" the page. Commented May 27, 2019 at 18:22
  • The Select An Element button mentioned at the bottom of this section doesn't focus the page. Neither does selecting the node from Elements panel > DOM Tree. Do those workflows work for you or do you need something else? Commented Jun 5, 2019 at 22:25
  • How is it different from the :focus option under force element state? Commented Mar 25 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.