I'm developing a Safari web app on Mac (created by File → Save to Dock). I encountered a few bugs that only occur in the web app, not in the website version. It seems I can't open the web console in the web app to see what goes wrong. I wonder what's the best way to debug Safari web apps? Thanks!
You can use the same tool in Safari as for debugging on iOS to debug in a macOS Safari Web App.
On macOS, launch Safari and in the Menu bar, go to Preferences → Advanced and check Show features for web developers.

In the menu bar, click on Develop → [Your current device] → [Your web app]

This will allow you to use all of the Safari web debugging tools with your web app.