Description
A SDK for web error and performance monitor using event subscription
Screenshot
Example
Online example: http://monitor.huzerui.com
Open chrome developer tool to see console information
Feature
Development
npm run watch // Watch tsfile change and compile by rollup
npm run server // Start a nodejs test server
Then visit localhost:3000
for example test
Build
npm run build
Test
npm run test
Installation
CDN
<script src="https://cdn.jsdelivr.net/npm/femonitor-web@latest/dist/index.min.js"></script>
NPM
npm i femonitor-web -S
Usage
Minimal options
import { Monitor } from "femonitor-web";
const monitor = Monitor.init();
monitor.on([event], (emitData) => {});
monitor.on(["jsError", "unhandleRejection"], (eventName, emitData) => {});
monitor.on("event", (eventName, emitData) => {});
Full options
export const defaultTrackerOptions = {
env: "dev",
reportUrl: "",
data: {},
error: {
watch: true,
random: 1,
repeat: 5,
delay: 1000
},
performance: false,
http: {
fetch: true,
ajax: true
},
behavior: {
watch: false,
console: [ConsoleType.error],
click: true,
queueLimit: 20
},
rrweb: {
watch: false,
queueLimit: 50,
delay: 1000
},
isSpa: true
};
const monitor = Monitor.init(defaultTrackerOptions);
Vue project
Sdk support Vue.config.errorHandler
to handle error for get detail component info. You just need to call useVueErrorListener
before create Vue instance.
monitor.useVueErrorListener(Vue)
React project
React supply a hook called componentDidCatch
for error listen and concept called ErrorBoundary which is enabled to catch errors at top and prevent app to shutdown. You can report it by yourself like below.
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
componentDidCatch(error, info) {
this.setState({ hasError: true });
reportError(error, info);
}
render() {
if (this.state.hasError) {
return <h1>Something went wrong.</h1>;
}
return this.props.children;
}
}
Support events
EventName | Description |
---|
jsError | winodw.onerror |
vuejsError | Vue.config.errorHandler |
unhandleRejection | window.onunhandledrejection |
resourceError | Resource request error |
batchErrors | Batch collection of error events, trigger every specified time interval |
reqError | Network request error |
reqStart | Network request start |
reqEnd | Network request end |
performanceInfoReady | Performance data is ready |
event | Includes all events above |