I was getting hanging in Ubuntu 22.04, but only in Firefox and Chromium. If I did nothing the web browsers went back to normal by themselves in about five minutes. My desktop and other apps were not affected, so I could logout and login to make the web browser(s) stop hanging immediately. This seemed to indicate that logging out and logging back in was clearing a cache of some kind.
Here is how I fixed the hanging permanently in Ubuntu 22.04.
Ubuntu uses inotify by default to monitor directories for changes. In Ubuntu the system limit on the number of files you can monitor is set low by default, so that Ubuntu's performance will be snappy on computers with low specs. You can get your current inotify file watch limit by running:
cat /proc/sys/fs/inotify/max_user_watches
When this limit is not enough to monitor all files inside a directory, the limit must be increased. You can set a new limit temporarily with:
sudo sysctl fs.inotify.max_user_watches=524288
sudo sysctl -p
To make your modified limit permanent run:
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
You may also need to pay attention to the values of max_queued_events and max_user_instances.
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
echo fs.inotify.max_user_instances=8192 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p