Skip to content

Instantly share code, notes, and snippets.

@jaynetics
Created March 6, 2019 10:49
Show Gist options
  • Save jaynetics/17aab10bdf78c49faf7ca9e085592bbc to your computer and use it in GitHub Desktop.
Save jaynetics/17aab10bdf78c49faf7ca9e085592bbc to your computer and use it in GitHub Desktop.
debug googlebot
<script>
if (window && window.navigator && /googlebot/i.test(window.navigator.userAgent)) {
var debug = function(key, value) {
var writeToBody = function() { document.body.setAttribute('data-' + key, value); };
if (document.body) writeToBody();
else window.addEventListener('DOMContentLoaded', writeToBody, false);
};
debug('googlebot', '1');
window.onerror = function(message, url, line, column, error) {
var fullMessage = JSON.stringify({
message: message,
url: url,
line: line,
column: column,
stack: (error && error.stack)
});
var randomNumber = Math.ceil(Math.random() * 1000000);
debug('googlebot-err-' + randomNumber, fullMessage);
};
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment