How to record the sound also in a screen recording if the headphones are connected?
You need to create a virtual audio output and use it as input. Try using Soundflower or similar software.
Hope it helps.