Bug 274818 - WKWebView randomly stops receiving mouse events
Summary: WKWebView randomly stops receiving mouse events
Status: RESOLVED CONFIGURATION CHANGED
Alias: None
Product: WebKit
Classification: Unclassified
Component: UI Events (show other bugs)
Version: Other
Hardware: Mac (Apple Silicon) macOS 14
: P2 Normal
Assignee: Abrar Rahman Protyasha
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2024-05-28 23:58 PDT by Jinyu Meng
Modified: 2024-06-06 05:43 PDT (History)
7 users (show)

See Also:


Attachments
Demo app to reproduce. (8.36 MB, application/zip)
2024-05-28 23:58 PDT, Jinyu Meng
no flags Details
Memory samples while the bug happens (103.41 KB, application/zip)
2024-05-31 07:14 PDT, Jinyu Meng
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jinyu Meng 2024-05-28 23:58:05 PDT
Created attachment 471534 [details]
Demo app to reproduce.

When the bug happens, the mouse will stop working on WKWebView completely. 
Click won't work. Right-click won't work. You can't open a context menu on it. The mouse cursor even won't show as "hand" on links.
It happens so randomly. It's hard to determine when it happens.
Scrolling and keyboard events still work.

Steps to reproduce:
0. Using the latest macOS/Xcode.
1. Create an empty app with WKWebView and two buttons to load URLs. The first URL can be anything you want, but it should be simple to save testing time. The second URL should be ChatGPT or Discord. This bug can also happen on other sites, but reproducing using these two is easier. (I don't know why.)
2. Click two buttons to let WKWebView navigate again and again.
3. Bug happens randomly. Then you can't click on the WKWebView anymore. Before you destroy this instance of WKWevView and create a new one, the problem won't be resolved.

It affects multiple third-party WebKit browsers, such as Orion and MenubarX. It happens so randomly, I'm so confused now.

I included a Demo app for you to test. There is also a video showing what it looks like when the bug happens. See how the mouse cursor changes when I move it onto the page.
Comment 1 Alexey Proskuryakov 2024-05-29 10:32:53 PDT
Thank you for the report. It sounds like this would be difficult to reproduce. When you can make it happen, it may be a good idea to file a Feedback Assistant report with a sysdiagnose (please post its ID if you do).
Comment 2 Simon Fraser (smfr) 2024-05-29 11:29:44 PDT
Could you tell us which macOS version you are testing on?
Comment 3 Radar WebKit Bug Importer 2024-05-29 13:39:39 PDT
<rdar://problem/128962118>
Comment 4 Jinyu Meng 2024-05-31 06:55:49 PDT
(In reply to Simon Fraser (smfr) from comment #2)
> Could you tell us which macOS version you are testing on?

I'm on the latest version 14.5 (23F79).
Comment 5 Jinyu Meng 2024-05-31 07:14:16 PDT
Created attachment 471556 [details]
Memory samples while the bug happens
Comment 6 Jinyu Meng 2024-05-31 07:19:56 PDT
(In reply to Alexey Proskuryakov from comment #1)
> Thank you for the report. It sounds like this would be difficult to
> reproduce. When you can make it happen, it may be a good idea to file a
> Feedback Assistant report with a sysdiagnose (please post its ID if you do).

I reported it with FB13814365. I also uploaded memory samples of related processes here on Bugzilla. Please check them out. Feel free to tell me if you need any additional information.
Comment 7 Simon Fraser (smfr) 2024-05-31 11:49:09 PDT
To reproduce more easily, wiggle the mouse fast after clicking in the document loading by the left button.
Comment 8 Simon Fraser (smfr) 2024-05-31 11:50:07 PDT
This was fixed by bug 273924.
Comment 9 Jinyu Meng 2024-05-31 20:52:05 PDT
(In reply to Simon Fraser (smfr) from comment #8)
> This was fixed by bug 273924.

I tried to run this demo with the latest WebKit I built locally before submitting this bug. My local webkit is on 102aa1b, after the commit in that PR. Are you sure it's fixed?
Comment 10 Jinyu Meng 2024-05-31 21:29:13 PDT
Did I do anything wrong while attempting to run my demo with locally built WebKit?

sudo Tools/Scripts/run-webkit-app /Users/megabits/Library/Developer/Xcode/DerivedData/TestWebKit-fcmryqzqjbceztbdxyapwumaazyk/Build/Products/Debug/TestWebKit.app --debug
Comment 11 Jinyu Meng 2024-05-31 22:25:45 PDT
I reproduced it again with the latest main d5b3ed8.
Comment 12 Jinyu Meng 2024-05-31 23:48:30 PDT
btw, Can you tell me how I can confirm the demo app is running with the WebKit I built?
Comment 13 Wenson Hsieh 2024-06-03 16:16:26 PDT
(In reply to Jinyu Meng from comment #12)
> btw, Can you tell me how I can confirm the demo app is running with the
> WebKit I built?

One quick way to verify whether or not it's properly using your custom WebKit (as opposed to system WebKit) is to either use Activity Monitor and examine the "Open Files and Ports" section for TestWebKit, to check whether WebCore.framework, JavaScriptCore.framework, and WebKit.framework are coming from a `/Users/…` or from a system path.

Another way is to `sample TestWebKit` briefly while it's running, and check the list of linked dylibs at the bottom of the output. The path to each dylib is printed out, and you can check where WebCore/JSC/WK is pointing to.
Comment 14 Jinyu Meng 2024-06-04 01:11:05 PDT
(In reply to Wenson Hsieh from comment #13)
> Another way is to `sample TestWebKit` briefly while it's running, and check
> the list of linked dylibs at the bottom of the output. The path to each
> dylib is printed out, and you can check where WebCore/JSC/WK is pointing to.

Thank you for telling me that. It seems the app is still using the system webkit. What did I do wrong? The run-webkit-app script didn't give me any error. Do I need to disable SIP to let it use my own WebKit?
Comment 15 Alexey Proskuryakov 2024-06-04 08:46:17 PDT
You shouldn't need to disable SIP, unless your app uses hardened runtime. `sudo` seems wrong, but should be harmless AFAIK.

Is your local build a debug ore release one?
Comment 16 Jinyu Meng 2024-06-05 05:50:23 PDT
(In reply to Alexey Proskuryakov from comment #15)
> You shouldn't need to disable SIP, unless your app uses hardened runtime.
> `sudo` seems wrong, but should be harmless AFAIK.
> 
> Is your local build a debug ore release one?

A new macOS project comes with hardened runtime by default. But I tested it after I removed that, and nothing changed.
I have both debug and release versions. And I tried both. None of them works.
Comment 17 Jinyu Meng 2024-06-05 06:04:09 PDT
I just tried to insert the DYLD_FRAMEWORK_PATH variable manually in Xcode. And it seems to work! Does that mean there is a bug in that start script?

By the way, the issue I reported disappeared. I can confirm it's fixed!
Comment 18 Alexey Proskuryakov 2024-06-05 10:13:21 PDT
> Does that mean there is a bug in that start script?

Actually, there might be indeed. When one is launching an app and not a CLI binary, it goes here (in webkitdirs.pm):

return system("open", "-W", "-a", $appPath, "--args", argumentsForRunAndDebugMacWebKitApp());

And with SIP enabled, `open` would lose DYLD environment variables. We probably need to do the same as in the code path below, passing archCommandLineArgumentsForRestrictedEnvironmentVariables(). It would also have to be renamed if used for `open` in addition to `arch`.

I don't have a proper OS to quickly test this, would you be willing to see if this makes it work as expected? Or perhaps even post a PR to fix this, if you want to.
Comment 19 Jinyu Meng 2024-06-06 04:53:37 PDT
(In reply to Alexey Proskuryakov from comment #18)
> I don't have a proper OS to quickly test this, would you be willing to see
> if this makes it work as expected? Or perhaps even post a PR to fix this, if
> you want to.

I did what you said, and it worked! I will post a PR later!
Comment 20 Jinyu Meng 2024-06-06 05:43:12 PDT
I posted a new bug report https://bugs.webkit.org/show_bug.cgi?id=275207 to track this.