UNPKG

3.07 kBMarkdownView Raw
1⚠️ Show JS Error
2=============
3
4[![NPM version](https://img.shields.io/npm/v/show-js-error.svg)](https://www.npmjs.com/package/show-js-error)
5[![NPM Downloads](https://img.shields.io/npm/dm/show-js-error.svg?style=flat)](https://www.npmjs.org/package/show-js-error)
6[![install size](https://packagephobia.com/badge?p=show-js-error)](https://packagephobia.com/result?p=show-js-error)
7
8Shows a message when an js error occurs in a browser.<br>
9Useful for developing and testing your site on mobile phones, smart TV, tablets and desktop.
10
11Shortly:<br>![Shortly](https://raw.githubusercontent.com/hcodes/show-js-error/master/images/simple.png?)<br><br>
12Detail:<br>![Detail](https://raw.githubusercontent.com/hcodes/show-js-error/master/images/detailed.png?)
13
14## Features
15- Support:
16 - Window errors
17 - Unhandled rejections
18 - CSP errors
19- [Small size](https://bundlephobia.com/package/show-js-error)
20- Only one JavaScript file
21- No dependencies
22- Short and detailed mode
23- Links with error hints on MDN and StackOverflow
24- UI
25- Integration with Github
26
27## Browsers
28- Chrome
29- Mozilla Firefox
30- Apple Safari
31- Microsoft Edge
32- Internet Explorer >= 11
33
34## Install
35```
36npm install show-js-error --save-dev
37```
38
39## Using
40
41### Browser
42With default settings:
43```html
44<script src="https://unpkg.com/show-js-error/dist/show-js-error.js"></script>
45```
46or with own settings:
47```html
48<script src="https://unpkg.com/show-js-error/dist/show-js-error.js"></script>
49```
50```js
51window.showJSError.setSettings({
52 reportUrl: 'https://github.com/hcodes/show-js-error/issues/new?title={title}&body={body}'
53});
54```
55
56### ES6 or TypeScript
57With default settings:
58```js
59import 'show-js-error';
60```
61or with own settings:
62```js
63import { showJSError } from 'show-js-error';
64showJSError.setSettings({
65 reportUrl: 'https://github.com/hcodes/show-js-error/issues/new?title={title}&body={body}'
66});
67
68showJSError.show(new Error('error'));
69```
70
71## API
72
73### .setSettings(settings)
74Set settings for error panel.
75
76```js
77showJSError.setSettings({
78 reportUrl: 'https://github.com/hcodes/show-js-error/issues/new?title={title}&body={body}', // Default: ""
79 templateDetailedMessage: 'My title\n{message}',
80 size: 'big' // for smart TV
81})
82```
83
84### .clear()
85Clear errors for error panel.
86
87### .show(error?: Error | object | string)
88Show error panel.
89
90```js
91showJSError.show();
92```
93
94Show error panel with transmitted error.
95```js
96showJSError.show({
97 title: 'My title',
98 message: 'My message',
99 filename: 'My filename',
100 stack: 'My stack',
101 lineno: 100,
102 colno: 3
103});
104
105// or
106showJSError.show('My error');
107
108// or
109showJSError.show(new Error('My error'));
110```
111
112### .hide()
113Hide error panel.
114
115### .toggleView()
116Toggle detailed info about current error.
117
118### .destruct()
119Detach error panel from page, remove global event listeners.
120
121## [Examples](./tests)
122- [Simple](http://hcodes.github.io/show-js-error/tests/many.html)
123- [Advanced](http://hcodes.github.io/show-js-error/tests/index.html)
124
125## [License](https://github.com/hcodes/show-js-error/blob/master/LICENSE)
126MIT License