1. Set a browser cookie:
- Open your Force.com site URL in your browser tab. (This is important - You won't see debug log until Setting cookie without opening your site)
- Open the Chrome DevTools Console by pressing Ctrl+Shift+J (Cmd+Opt+J on macOS).
- Execute a command to set the cookie. (Copy and paste the below command and click Enter)
If you use a .force.com domain, use this command.
document.cookie="debug_logs=debug_logs;domain=.force.com";
If you use a custom domain (for example, yourCustomDomain.com), use this command.
document.cookie="debug_logs=debug_logs;domain=yourCustomDomain.com";
2. Find the name of your site’s guest user:
- From Setup, enter Sites in the Quick Find box, then select Sites.
- Select your site from the Site Label column.
- Select Public Access Settings | View Users.
3. Set a user-based trace flag on the guest user.
- From Setup, enter Debug Logs in the Quick Find box, then click Debug Logs.
- Click New.
- Set the traced entity type to User.
- Open the lookup for the Traced Entity Name field, and then find and select your guest user.
- Assign a debug level to your trace flag.
- Click Save.
Reference: