
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
activity-event-listener
Advanced tools
Listen to a web application unhandle exceptions/errors, http success and failure request, user navigation, promise resolve and reject activity
Using this package allows you to listen for browser events like unhandle exceptions/errors, http success and failure, unhandle promises, etc.
You can use this package to monitor for user activities and sending the events to a server for logging purposes.
npm install activity-event-listener --save
Event Listener
import {subscribe} from 'activity-event-listener';
const options = {
promiseCatch: true,
httpFailure: true
}
subscribe(function(events){
// This function is called whenever an event is triggered
}, options)
Event Listener Options
You can also specify which event you want to listen by altering the options
property
const options = {
promiseCatch: true, // Trigger when promise catch is invoked. default true
httpSuccess: true, // Triggered when an http request is completed successfully. default true
httpFailure: true, // Triggered an event when an http request failed. default true
unhandleRejection: true, // Triggered when an unhandle Rejection error is thrown. default true
linkClick: true, // Triggered when any html anchor tag (a link) is clicked. default false
buttonClick: true // Triggered when any html button is clicked. default false,
ignoreUrl: 'https://example.com/logging-endpont' // Provide the url link that should be ignored (not tracked) if you plan to be sending the events to a server.
}
Trigger Events
You can also listen for frontend framework specific events and trigger an event.
import {subscribe, options, trigger} from 'activity-event-listener';
// file1.js
subscribe(function(event){
// log the event or send it to server for storage
})
// file2.js
Vue.config.errorHandler = function(error) {
let customEvent = {
...error,
message: error && error.message,
stack: error && error.stack,
isError: true
}
trigger(customEvent, options.unhandleRejection);
}
import {subscribe} from 'activity-event-listener';
subscribe(function(events){
// Push the events to a logging server
const xhttp = new XMLHttpRequest();
xhttp.onload = function() {
console.log('Activity Sent')
};
xhttp.open("POST", "/activity-event-log/", true);
xhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhttp.send(JSON.stringify(events));
}, {ignoreUrl: 'https://myserver.com/logging-endpont'})
FAQs
Listen to a web application unhandle exceptions/errors, http success and failure request, user navigation, promise resolve and reject activity
The npm package activity-event-listener receives a total of 2 weekly downloads. As such, activity-event-listener popularity was classified as not popular.
We found that activity-event-listener demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.