How can I record an app in background
It is not immediately possible to record the windows of Chrome/Safari when they're not displayed on screen, as they really aren't rendered when not needed.
You could possibly make a more involved setup by running a virtualized operating system with Chrome that you can record indepedently on whether it is shown on the monitor or not.
Similarly you could do something like running Chrome under X11 using x11vnc or similar to enable off-screen recording.
There is also the possibility of using Headless Chrome by way of for example the puppeteer-video-recorder plugin to record a video - however I think it would be quite a hassle to get setup.
As for routing the audio as you wish, you should be able to relatively easily set this up by using the Loopback program.