Have you tried reinstalling Windo.... er ... I mean macOS? But seriously though, you could create another account and see if the problem is occurring there. If not then it's likely some third-party software. Did you update the Mac from an earlier OS or did you do a clean install?