1.2.4 • Published 5 months ago

@saekitominaga/report-js-error v1.2.4

Weekly downloads
1
License
MIT
Repository
github
Last release
5 months ago

Send script error information to endpoints

npm version test status

Detects the error event of the window object and sends error information to the endpoint.

Demo

Examples

import ReportJsError from '@saekitominaga/report-js-error';

const reportJsError = new ReportJsError('https://report.example.com/js', {
  fetchParam: {
    location: 'loc',
    message: 'msg',
    filename: 'file',
    lineno: 'line',
    colno: 'col',
  },
  fetchContentType: 'application/json',
  fetchHeaders: {
    'X-Requested-With': 'hoge',
  },
  allowFilenames: [
    /\.js$/,
    /\.mjs$/,
  ],
  denyUAs: [
    /Googlebot\/2.1;/,
  ],
});
reportJsError.init();

Constructor

new ReportJsError(endpoint: string, option: {
  fetchParam?: {
    location: string; // Field name when sending `location` to an endpoint. The default value when omitted is `location`. (e.g. location=https%3A%2F%2Fexample.com%2Fpath%2Fto&message=(omit)&filename=(omit)&lineno=(omit)&colno=(omit) )
    message: string; // Field name when sending `ErrorEvent.message` to an endpoint. The default value when omitted is `message`. (e.g. location=(omit)&message=ReferenceError%3A+hoge+is+not+defined&filename=(omit)&lineno=(omit)&colno=(omit) )
    filename: string; // Field name when sending `ErrorEvent.filename` to an endpoint. The default value when omitted is `filename`. (e.g. location=(omit)&referrer=(omit)&message=(omit)&filename=https%3A%2F%2Fexample.com%2Fpath%2Fto&lineno=(omit)&colno=(omit) )
    lineno: string; // Field name when sending `ErrorEvent.lineno` to an endpoint. The default value when omitted is `lineno`. (e.g. location=(omit)&referrer=(omit)&message=(omit)&filename=(omit)&lineno=10&colno=(omit) )
    colno: string; // Field name when sending `ErrorEvent.colno` to an endpoint. The default value when omitted is `colno`. (e.g. location=(omit)&referrer=(omit)&message=(omit)&filename=(omit)&lineno=(omit)&colno=20 )
  },
  fetchContentType?: 'application/x-www-form-urlencoded' | 'application/json'; // `Content-Type` header to be set in `fetch()` request.
  fetchHeaders?: HeadersInit; // Header to add to the `fetch()` request. <https://fetch.spec.whatwg.org/#typedefdef-headersinit>
  denyFilenames?: RegExp[]; // If the script filename (`ErrorEvent.filename`) matches this regular expression, do not send report
  allowFilenames?: RegExp[]; // If the script filename (`ErrorEvent.filename`) matches this regular expression, send report
  denyUAs?: RegExp[]; // If a user agent matches this regular expression, do not send report
  allowUAs?: RegExp[]; // If a user agent matches this regular expression, send report
} = {})

Parameters

  • If neither denyFilenames nor allowFilenames is specified, any user agent will be accepted.
  • If neither denyUAs nor allowUAs is specified, any file name will be accepted.
1.2.4

5 months ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.0

3 years ago