Bug 226025 - document and window does not initially have focus in WKWebView
Summary: document and window does not initially have focus in WKWebView
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: Safari 14
Hardware: iPhone / iPad iOS 14
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-05-20 09:20 PDT by raon0211
Modified: 2021-06-11 23:03 PDT (History)
6 users (show)

See Also:


Attachments
videos that show the difference between mobile safari and wkwebview (1.14 MB, application/zip)
2021-05-20 09:20 PDT, raon0211
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description raon0211 2021-05-20 09:20:40 PDT
Created attachment 429179 [details]
videos that show the difference between mobile safari and wkwebview

When loading webpages in WKWebView, document and window does not have initial focus.
(`document.hasFocus()` returns `false` initially.)

After receiving some user interactions such as touch,
the `window`'s focus event fires and `document.hasFocus()` starts to return `true`.

This is strange since in Mobile Safari, `document` and `window` have focus from the beginning.

Since JavaScript libraries such as SWR or React Query revalidates the AJAX requests on window's focus events,
this leads to extra XHR requests to fire when accessing sites using such libraries.


The videos in the attached ZIP file below show the difference of Mobile Safari and WKWebView:

In Mobile Safari, `document` and `window` immediately have focus.
In WKWebView (Facebook In-app Web Browser), `document` and `window` does not have focus until user touch.

The test page used in the video is https://service-alpha.toss.im/test/focus-test.


---
Thread in WebKit slack: https://webkit.slack.com/archives/CU5LWFM28/p1621516267010100
Comment 1 raon0211 2021-05-20 09:21:46 PDT
The issue remains in many in-app browsers implemented with WKWebView.
Comment 2 Radar WebKit Bug Importer 2021-05-27 09:21:18 PDT
<rdar://problem/78571876>