Bug 226025

Summary: document and window does not initially have focus in WKWebView
Product: WebKit Reporter: raon0211
Component: WebKit Misc.Assignee: Nobody <webkit-unassigned>
Status: NEW ---    
Severity: Normal CC: achristensen, cdumez, ggaren, simon.fraser, webkit-bug-importer, wenson_hsieh
Priority: P2 Keywords: InRadar
Version: Safari 14   
Hardware: iPhone / iPad   
OS: iOS 14   
Attachments:
Description Flags
videos that show the difference between mobile safari and wkwebview none

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>