We all know that Googlebot parses and executes JavaScript, but it’s still a bit of a mystery to debug it when something goes wrong.

Using the Fetch as Google page in the Search Console, we can see what the Googlebot thinks your page looks like. But what if it just comes back empty, or looks broken?

This simple little script will show JS errors in a red box covering the page, hopefully readable enough on the thumbnail that Search Console will show you.

Just put this script as high up as possible on the page to catch all errors. If you need to use this in production; only show it to Googlebot, or on a specific private URL.

If you want to get fancy you can send the error along with the User Agent to your analytics service of choice, and then filter out Googlebot errors that way.