如何强迫网页认为它是焦点或焦点? [英] How to force a webpage to think that it is in or out focus?

查看:193
本文介绍了如何强迫网页认为它是焦点或焦点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个Web应用程序(以了解WebSocket和自适应行为),该应用程序轮询不同的社交媒体网站并在一个地方显示所有最新更新.我想让页面在焦点不清晰时停止更新,然后在焦点不清晰时再次更新.

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.

我的问题是:
有没有一种方法可以强制"选项卡以使其处于焦点或焦点之外,就像DevTools中的强制元素状态一样,但要针对整个选项卡.

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.

我正在Windows 10上运行Chrome.我找不到使用DevTools进行此操作的方法,也不想为这样简单的事情设置整个测试框架.

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.

谢谢您的时间.

推荐答案

  1. 打开命令菜单.
  2. >
  3. 运行Emulate a focused page命令.
  1. Open the Command Menu.
  2. Run the Emulate a focused page command.

如果您创建 Live Expression 并将其设置为document.hasFocus()的表达式,您会看到在运行Emulate a focused page命令后页面始终认为它是焦点.

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.

这篇关于如何强迫网页认为它是焦点或焦点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆