If you find that your Raspberry Pi 3 (or any above), those with built in WiFi and Bluetooth, loses the WiFi connection after a period of inactivity, then this thread on the Raspberry Pi Forums, which will open in a new tab, might be of interest. Have a read. If you want to miss out on the preliminaries of the thread, start reading here instead.
The problem is likely to be the power saving mode of the Wifi. To check the current setting:
sudo iw dev wlan0 get power_save
If you are/will be affected, it will reply with:
If so, all you need to do is:
sudo iw dev wlan0 set power_save off
I’m not affected yet, but I’m making a note here, just in case!