Bug 257450 - document.focus or window onblur not trigger util a mouse move or click user gesture happened when an url-scheme launch dialog shows
Summary: document.focus or window onblur not trigger util a mouse move or click user g...
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: Safari 16
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-05-29 02:33 PDT by Jeason Xu
Modified: 2023-06-05 02:34 PDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeason Xu 2023-05-29 02:33:14 PDT
When launch an url scheme on safari, safari shows a lauch dialog. This dialog should take back focus from document, but when I console "document.hasFocus()", this value still be true. Util I move my mouse, this value changes. I use "document.hasFocus()" changes when lauch a application by url scheme to detect if an application is installed or not. This works in other browser.
Comment 1 Jeason Xu 2023-05-29 02:39:04 PDT
Here is demo code:
const launchSharingApp = (urlScheme) => {
  if (!urlScheme) return;
  const frameId = 'url-scheme-frame-id';
  let tempIframe = document.getElementById(frameId);
  if (!tempIframe) {
    tempIframe = document.createElement('iframe');
    tempIframe.id = frameId;
    tempIframe.style.display = 'none';
    document.body.appendChild(tempIframe);
  }
  tempIframe.contentWindow.location.href = urlScheme;
  setTimeout(() => {
    if (!document.hasFocus()) {
      /** if lost focus very fast, it means broswer's own confirm dialog shows.
       * User has no chance to touch other app */
      console.log('app installed');
    }
  }, 50);
};
launchSharingApp('...')
Comment 2 Radar WebKit Bug Importer 2023-06-05 02:34:16 PDT
<rdar://problem/110253831>