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 |
|
8 | Shows a message when an js error occurs in a browser.<br>
|
9 | Useful for developing and testing your site on mobile phones, smart TV, tablets and desktop.
|
10 |
|
11 | Shortly:<br>![Shortly](https://raw.githubusercontent.com/hcodes/show-js-error/master/images/simple.png?)<br><br>
|
12 | Detail:<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 | ```
|
36 | npm install show-js-error --save-dev
|
37 | ```
|
38 |
|
39 | ## Using
|
40 |
|
41 | ### Browser
|
42 | With default settings:
|
43 | ```html
|
44 | <script src="https://unpkg.com/show-js-error/dist/show-js-error.js"></script>
|
45 | ```
|
46 | or with own settings:
|
47 | ```html
|
48 | <script src="https://unpkg.com/show-js-error/dist/show-js-error.js"></script>
|
49 | ```
|
50 | ```js
|
51 | window.showJSError.setSettings({
|
52 | reportUrl: 'https://github.com/hcodes/show-js-error/issues/new?title={title}&body={body}'
|
53 | });
|
54 | ```
|
55 |
|
56 | ### ES6 or TypeScript
|
57 | With default settings:
|
58 | ```js
|
59 | import 'show-js-error';
|
60 | ```
|
61 | or with own settings:
|
62 | ```js
|
63 | import { showJSError } from 'show-js-error';
|
64 | showJSError.setSettings({
|
65 | reportUrl: 'https://github.com/hcodes/show-js-error/issues/new?title={title}&body={body}'
|
66 | });
|
67 |
|
68 | showJSError.show(new Error('error'));
|
69 | ```
|
70 |
|
71 | ## API
|
72 |
|
73 | ### .setSettings(settings)
|
74 | Set settings for error panel.
|
75 |
|
76 | ```js
|
77 | showJSError.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()
|
85 | Clear errors for error panel.
|
86 |
|
87 | ### .show(error?: Error | object | string)
|
88 | Show error panel.
|
89 |
|
90 | ```js
|
91 | showJSError.show();
|
92 | ```
|
93 |
|
94 | Show error panel with transmitted error.
|
95 | ```js
|
96 | showJSError.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
|
106 | showJSError.show('My error');
|
107 |
|
108 | // or
|
109 | showJSError.show(new Error('My error'));
|
110 | ```
|
111 |
|
112 | ### .hide()
|
113 | Hide error panel.
|
114 |
|
115 | ### .toggleView()
|
116 | Toggle detailed info about current error.
|
117 |
|
118 | ### .destruct()
|
119 | Detach 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)
|
126 | MIT License
|