L O A D I N G

Project Status

npmnpm downloads

buildbuild push package

check typeslinttest

code coverage

deploy web documentationweb documentation

Use case

A small client side error reporter. Include it in your website and every uncaught error and unhandled promise rejection in your visitors' browsers is sent to your server, together with details about the browser, the operating system and the page. You learn about problems in production without asking users to open their developer tools.

Features included:

  • Registers itself on load, no further code needed.
  • Reports each distinct error only once per page view.
  • Detailed browser, engine, operating system and device information via the optional ua-parser-js.
  • Filters for known noise and unsupported browsers, extendable with your own rules.
  • Hooks for successful, failed and ignored reports.

Installation

Install it via a package manager and import it once in your entry module:

npm install errorreporter
import 'errorreporter'

Or include the self-contained bundle "bundle/index.js" as early as possible in your HTML, ideally as first script. It contains all needed polyfills, has no dependencies, runs synchronously as a plain (non module) script in any environment and is then available as global "errorreporter":

<script src="https://unpkg.com/errorreporter@latest/bundle/index.js"></script>

For browser details load ua-parser-js before, so that a global "UAParser" exists when the error reporter is loaded. Without it reports contain the raw user agent only and browser based filter rules do not apply:

<script src="https://unpkg.com/ua-parser-js@2/dist/ua-parser.min.js"></script>
<script src="https://unpkg.com/errorreporter@latest/bundle/index.js"></script>

Example

This live example replaces the network request with a function that shows the reported message:

<div id="error-output"></div>
errorreporter.globalContext.fetch = (url, options) => {
    document.querySelector('#error-output').textContent =
        JSON.parse(options.body).errorMessage

    return Promise.resolve()
}
Promise.reject('Example error')

Receiving reports on the server

Each report is a "PUT" request with a JSON body to "/error_report" on the host the page was loaded from. Store or forward it as you like. The body contains:

  • "errorMessage", "stack", "url", "lineNumber" and "columnNumber": The error itself.
  • "absoluteURL": Address of the page where it happened.
  • "userAgent" and "technologyDescription": Raw user agent and a readable summary like "Firefox 140 (140.0 | Gecko 140.0) | Windows 10".
  • "issuesToIgnore": The filter rules active on the client.

Configuration

All settings are properties of the exported "errorHandler". Set them right after loading, before the first error occurs:

import {errorHandler} from 'errorreporter'

errorHandler.reportPath = '/api/client-error'
errorHandler.additionalIssuesToIgnore = [
    {errorMessage: /ResizeObserver loop/},
    {browser: {name: 'Safari', major: '15'}}
]
errorHandler.failedHandler = (error) => console.warn(error)
  • "reportPath": Path on the current host to send reports to. Defaults to "/error_report".
  • "additionalIssuesToIgnore": Your own filter rules, added to the built-in ones.
  • "issuesToIgnore": Replaces the built-in filter rules. They cover old Internet Explorer and Firefox versions and common messages caused by browser extensions or the environment.
  • "reportedHandler": Called with the response after a report was sent.
  • "failedHandler": Called if sending fails. Shows a browser alert by default.
  • "issueToIgnoreHandler": Called for filtered errors. If a rule without "errorMessage" matched, i.e. an unsupported browser, it shows an alert asking the visitor to upgrade by default.

Filter rules

A rule is a partial error description. It matches if all given properties match: strings have to be equal, regular expressions have to match. Available properties are "errorMessage", "technologyDescription", "ua" and the objects "browser" ("name", "major", "version"), "engine" and "os" ("name", "version").

Development

yarn install
yarn build
yarn test

About this website

Provider ofhttps://tsickert.com/errorreporter:
Torben Sickert
Waldstraße 29
79194 Gundelfingen i.Br.
Phone: +49 (0) 176 / 10 248 185
Email: [email protected]
Website: https://tsickert.com
homedeDE: StartseitefrFR: Maison

Disclaimer

Liability for content

The content of our pages has been prepared with the utmost care. However, we cannot guarantee the accuracy, completeness or timeliness of the content. As a service provider, we are responsible for our own content on these pages under general law. However, we are not obliged to monitor transmitted or stored third-party information or investigate circumstances that indicate illegal activity. Obligations to remove or block the use of information under general law remain unaffected. Liability in this respect is only possible from the time we become aware of a specific infringement. Upon becoming aware of any such legal violations, we will remove this content immediately.

Liability for links

Our website contains links to external third-party websites whose content is beyond our control. We therefore cannot accept any responsibility for such third-party content. The respective provider or operator of each linked site is always responsible for its content. The linked sites were checked for possible legal violations when the links were created. No illegal content was apparent at that time. However, continuous monitoring of linked sites is not reasonable without specific evidence of a legal violation. If we become aware of any legal violations, we will remove the relevant links immediately.

Copyright

Content and works on these pages created by the site operators are subject to German copyright law. Reproduction, adaptation, distribution and any use beyond the scope of copyright law require the written consent of the respective author or creator. Downloads and copies of this site are permitted for private, non-commercial use only. Where content on this site was not created by the operator, third-party copyrights are respected. In particular, third-party content is identified as such. If you become aware of a copyright infringement, please notify us. Upon becoming aware of any legal violations, we will remove the relevant content immediately.

Privacy Policy

You can generally use our website without providing personal data. Where personal data (such as names, addresses or email addresses) is collected on our pages, this is, wherever possible, always done on a voluntary basis. This data will not be passed on to third parties without your express consent. Please note that data transmission over the internet (for example, when communicating by email) may have security vulnerabilities. It is not possible to completely protect data against access by third parties. We expressly object to the use by third parties of contact details published to meet legal notice requirements for sending unsolicited advertising or information. The site operators expressly reserve the right to take legal action if unsolicited advertising, such as spam emails, is sent.

Content Delivery Network (Cloudflare)

We use Cloudflare (Cloudflare, Inc., 101 Townsend St., San Francisco, CA 94107, USA) to protect and speed up our website. This constitutes a legitimate interest within the meaning of Art. 6(1)(f) GDPR. Cloudflare processes log data (including IP addresses) and sets technically necessary cookies to defend against malicious bot traffic. We have concluded a Data Processing Addendum (DPA) with Cloudflare based on the EU Standard Contractual Clauses. Cloudflare is certified under the EU-U.S. Data Privacy Framework.

Privacy Statement for a possible use of Google Analytics

This website may use Google Analytics 4, a web analytics service provided by Google Ireland Limited ("Google", Gordon House, Barrow Street, Dublin 4, Ireland). If it is used, data is processed solely on the basis of your express consent (Art. 6(1)(a) GDPR). Google Analytics uses cookies that enable analysis of how you use the website. Information generated by these cookies about your use of this website is transmitted to and stored on a Google server; transfer of data to third countries (such as the United States) cannot be ruled out. IP anonymization is enabled by default on this website, so Google truncates your IP address within a member state of the European Union or another state party to the Agreement on the European Economic Area before transmission. You may withdraw your consent at any time with effect for the future through the cookie settings (our consent tool), or prevent data collection by using the official Google browser add-on.

Copyright Statement

Unless noted otherwise, all artwork on this website is protected property of the website author. Any use for commercial purpose, reproduction and publication requires the author's written permission. Commercial work created in cooperation or bound by contract with third parties are specifically marked. Respective copyrights apply.

top