visit
In our
<head>
tag, we added the following script:<script type=”text/javascript”>
var consoleErrors = [];
function logError(e) {
try {
consoleErrors.push([e.error.stack, e.lineno, e.timeStamp]);
} catch (e) {}
};
window.addEventListener("error", logError);
</script>
<form id="contactForm">
<label for="email">Your email address</label>
<input id="email" type="email" name="email" required="true">
<label for="name">Your name</label>
<input id="name" type="text" name="name" required="true">
<label for="comments">Description</label>
<textarea id="comments" name="comments" rows="3"></textarea>
<input id="documentUrl" type="hidden" name="documentUrl">
<input id="console" type="hidden" name="console">
<input type="submit" value="Send">
</form>
<script type=”text/javascript”>
$('#contactForm').on('submit', function(e) {
e.preventDefault();
let payload = {
email: $('#email').val(),
name: $('#name').val(),
comments: $('#comments').val(),
documentUrl: location.href,
errors: consoleErrors,
};
$.post('/contact', payload, function(resp) {
$('#contactSuccess').html('Contact form sent.').show();
});
window.setTimeout(function() { $('#contactModal').modal('hide')}, 1000);
return false;
});
<script>
You’ll note that in the example above, it is assumed that the contact us form is a modal that appears on the page, which prevents the site from reloading and therefore losing the
logErrors
object. However, if you need to send a user to another page, you can store the error output in local storage and retrieve it when you need to.That’s all! Then the next time someone writes in concerned about an issue, you’ll have the specific stack trace they are referring to right in the email.