Hello Kanihoncho,
We'll need to take some additional steps to isolate this behavior further so it can be addressed.
The first step will be to boot your iMac into safe mode using the process below:
1. Shut down your Mac.
2. Turn on your Mac and continue to press and hold the power button until you see the startup options window.
3. Select your startup disk, then press and hold the Shift key while clicking “Continue in Safe Mode.”
4. Log in to your Mac. You might be asked to log in again.
You can also find those steps in this resource: How to use safe mode on your Mac - Apple Support
It can take a few extra minutes to boot into safe mode. Your screen may flash or flicker while in safe mode. Those behaviors are expected. Testing in safe mode runs a check on your disk, removes some cached files, and can help isolate conflicts with startup items. Once you've tested that behavior in safe mode, you can restart to leave safe mode.
Should that still persist, is this happening with just Safari, or does this also occur with other web browsers?
Let us know, and we'll keep moving forward based on your results.