# Logging Javascript errors in production

DevFeed: [Logging Javascript errors in production](<https://devfeed.tech/articles/logging-javascript-errors-in-production-19999.md>)

Original publisher: [Read original article](<http://engineering.hackerearth.com/2016/01/29/hackerearth-logging-javascript-errors-production/>)

Published: 2016-01-29T00:00:00Z

Content type: tutorial

Language: en

Sources: [HackerEarth](<https://devfeed.tech/sources/hackerearth.md>)

Topics: [error tracking](<https://devfeed.tech/topics/error-tracking.md>), [Cross-origin resource sharing (CORS)](<https://devfeed.tech/topics/cors.md>), [Amazon S3](<https://devfeed.tech/topics/amazon-s3.md>), [JavaScript](<https://devfeed.tech/topics/javascript.md>), [Amazon Web Services](<https://devfeed.tech/topics/aws.md>), [browsers](<https://devfeed.tech/topics/browsers.md>), [Web](<https://devfeed.tech/topics/web.md>), [cURL](<https://devfeed.tech/topics/curl.md>)

Tags: [aws](<https://devfeed.tech/tags/aws.md>), [browsers](<https://devfeed.tech/tags/browsers.md>), [curl](<https://devfeed.tech/tags/curl.md>), [errors](<https://devfeed.tech/tags/errors.md>), [http](<https://devfeed.tech/tags/http.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [logging](<https://devfeed.tech/tags/logging.md>), [s3](<https://devfeed.tech/tags/s3.md>)

## AI overview

This article explains how to implement JavaScript error logging in production using errorception. It describes a CORS-related integration problem caused by serving static files from Amazon S3 through another domain, and outlines configuring S3 CORS headers so browser error details can be posted to the logging service.

## Source excerpt

We had implemented a javascript logger to capture the pesky issues our users faced and had problems when using the site. When we came up with the idea, we thought it would be just a five minute job where we would just have to add a snippet and would be done, but as it is well know, nothing is simple when it comes to real world production issues. After analyzing a lot of loggers, we decided to use errorception as our javascript logger. It was simple in its approach and it provided the data we needed. This was the easy part, next came the part of integration, and yes there was a snippet which we just had to paste in our base javascript file, but one thing we had forgotten, CORS. We host our static files on S3 and they are served via fastly, because of which they are delivered through another domain. The error tracking snippet could not log the errors because 'window.onerror' would not return the necessary stack trace and information. Many of you may have heard about CORS, it is a mechanism that allows restricted resources (e.g. fonts) on a web page to be requested from another domain outside the domain from which the resource originated. For security reasons, browsers restrict cross-origin HTTP requests initiated from within scripts. The only way to solve this and get errors to be posted to errorception was to allow CORS in the header of the static files. After some research (errorception also has a good blog on it), we finally managed to have the error logging implemented. Below are the steps we had to go through: Configuring S3 S3 has this unnecessarily complicated "CORS configuration" that you need to create. Here's the steps to get that right: Log into your AWS S3 console, select your bucket, and select "Properties". S3 CORS configurations seem to apply at the level of the bucket, and not the file. I have no clue why. Expand the "Permissions" pane, and click on "Add CORS configuration" or "Edit CORS configuration" depending on what you see. You should already be p