0

I was trying to use window.setInterval() API to check the result of document.hasfocus(). Normally, when we click to another browser tab or another application, the document.hasfocus() of one page will return false. However, when I tried to print a webpage in Edge, and with the print dialog opened, I found the document.hasfocus() always returns true, and it shouldn't be, cause the print dialog doesn't belong to the webpage. This only happens on Windows platform(It works fine on Edge for Mac). In fact, this also happens on Chrome for Windows10.

The repro steps:

  1. Open any webpage with Edge.
  2. Open devtools and keep checking document.hasFocus().
  3. Print the webpage and shows the print dialog of Edge.
  4. document.hasFocus() always show true no matter where we click to(another tab or another application).

I am not sure whether this is a bug of Edge or Web APIs, so I think I should submit an issue here to seek for some help. Any workaround that can fix this? Thanks in advance for your kind help.

  • I tried to test the issue with the MS Edge(87.0.664.75) and Google Chrome browsers on Windows and MAC OS. I am able to produce the said issue in MS Edge and Google Chrome browser on Windows OS. It can be possible that the issue is related to the Chromium browser engine. I suggest you try to submit the said issue [here](https://bugs.chromium.org/p/chromium/issues/list). As a workaround, I suggest you make tests with the [FocusEvent](https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent). Thanks for your understanding. – Deepak-MSFT Jan 12 '21 at 07:23
  • Thank you for your reply, I've submitted the issue in the link. And the focus event is not enough for my situation but still, thanks for your suggestion. – yan-stack Jan 12 '21 at 09:45
  • If you try to provide more information for your requirement then we can try to find some workaround for it and try to provide suggestions. Thanks for your understanding. – Deepak-MSFT Jan 13 '21 at 06:04
  • I was trying to detect the change of document.hasFocus(), if the result changes, I would do something. The reason why I cannot use FocusEvent is that I have some iframes in my page. And these iframes infect the focus event of the main page. – yan-stack Jan 13 '21 at 08:18
  • In that case, I suggest you try to use the combination of focus event and element.focus to see whether it gives the desired result. – Deepak-MSFT Jan 14 '21 at 02:30
  • Yes I tried this, but the iframes in my page are some third-party add-ins, and I cannot control them thus I cannot register element.focus on them. It's a little bit complicate in my situation that's why I tried to poll for the result of document.hasFocus(). – yan-stack Jan 14 '21 at 04:53
  • If the webpage contains any other element that is available to check the focus then you can try to check it. – Deepak-MSFT Jan 15 '21 at 08:39

0 Answers0