Bug 229139 - document.hasFocus() returns true for unfocused pages
Summary: document.hasFocus() returns true for unfocused pages
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: Gtk, InRadar
Depends on:
Blocks:
 
Reported: 2021-08-16 07:33 PDT by Carlos Garcia Campos
Modified: 2021-08-19 01:47 PDT (History)
8 users (show)

See Also:


Attachments
Test (225 bytes, text/html)
2021-08-16 07:33 PDT, Carlos Garcia Campos
no flags Details
Patch (4.44 KB, patch)
2021-08-16 07:36 PDT, Carlos Garcia Campos
aperez: review+
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (4.68 KB, patch)
2021-08-17 00:27 PDT, Carlos Garcia Campos
no flags Details | Formatted Diff | Diff
Patch for landing (30.35 KB, patch)
2021-08-18 02:29 PDT, Carlos Garcia Campos
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch for landing (29.61 KB, patch)
2021-08-18 03:31 PDT, Carlos Garcia Campos
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch for landing (29.61 KB, patch)
2021-08-18 23:37 PDT, Carlos Garcia Campos
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos Garcia Campos 2021-08-16 07:33:20 PDT
Created attachment 435599 [details]
Test

This can be reproduced with the attached test, the web view title shows whether the document has the focus or not at any time. Move the focus to a new tab in MiniBrowser to see that it remains true for the hidden tab. The problem is that we are always claiming to have the focus when the web view is in the active window. This is not happening in safari, but I don't understand why. I noticed this because ikea.com website stores the active widget in localstorage using document.hasFocus(). When opening multiple tabs it starts writing local storage like crazy making the network and web processes consume 100% cpu. It doesn't happen when using multiple windows instead of tabs, because in that case only the tab in the active window returns true for document.hasFocus().
Comment 1 Carlos Garcia Campos 2021-08-16 07:36:20 PDT
Created attachment 435600 [details]
Patch
Comment 2 Adrian Perez 2021-08-16 07:45:42 PDT
Comment on attachment 435600 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=435600&action=review

> Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebKitWebView.cpp:801
> +static void testWebViewDocumentFocus(WebViewTest* test, gconstpointer)

Nice test, by the way :)
Comment 3 Carlos Garcia Campos 2021-08-16 23:59:29 PDT
The gtk unit test is failing under xvfb, I'll fix it. But I need help with the cocoa unit tests. WebAuthenticationPanel test looks unrelated, but maybe the test assumes the view has the focus while the panel is open or something like that?
Comment 4 Carlos Garcia Campos 2021-08-17 00:16:24 PDT
In the case of gtk I think the problem is that the toplevel window focus is given to the window by the window manager, so under xvfb we never set the WindowIsActive flag because there's no a window manager.
Comment 5 Carlos Garcia Campos 2021-08-17 00:27:50 PDT
Created attachment 435668 [details]
Patch
Comment 6 Carlos Garcia Campos 2021-08-18 02:28:55 PDT
The cocoa tests failures are because the credential container requires the document to be focused and the page isn't actually focused, now caught by document.hasFocus(). We just need to focus the view in all the tests.
Comment 7 Carlos Garcia Campos 2021-08-18 02:29:24 PDT
Created attachment 435755 [details]
Patch for landing
Comment 8 Carlos Garcia Campos 2021-08-18 03:31:27 PDT
Created attachment 435758 [details]
Patch for landing
Comment 9 EWS 2021-08-18 23:31:22 PDT
ChangeLog entry in Tools/ChangeLog contains OOPS!.
Comment 10 Carlos Garcia Campos 2021-08-18 23:37:27 PDT
Created attachment 435847 [details]
Patch for landing
Comment 11 EWS 2021-08-19 01:46:12 PDT
Committed r281228 (240665@main): <https://commits.webkit.org/240665@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 435847 [details].
Comment 12 Radar WebKit Bug Importer 2021-08-19 01:47:18 PDT
<rdar://problem/82115580>