This package has been deprecated

Author message:

This package has been moved to @w0s/report-js-error

@saekitominaga/report-js-error
TypeScript icon, indicating that this package has built-in type declarations

1.2.4 • Public • Published

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

endpoint [required]
URL of the endpoint
option [optional]
Information such as transmission conditions
  • 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.

Readme

Keywords

Package Sidebar

Install

npm i @saekitominaga/report-js-error

Weekly Downloads

0

Version

1.2.4

License

MIT

Unpacked Size

49.1 kB

Total Files

7

Last publish

Collaborators

  • saekitominaga