npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

browlog

v1.3.4

Published

Instant error reporting from browser to your webhook channel of choice

Downloads

11

Readme

Browlog

npm

Automatically log any errors happening in your app!

Disclaimer

Browlog is simply just an extension which instantly post to any specified reporter(s).

This means, this extension doesn't have a dashboard like other monitoring tools since this is a very lightweight error logger by utilizing error events.

If this is enough for your needs, then let's get started!

Installation

npm i browlog

Usage

Browlog uses singleton approach, you need to call the init as following:

import browlog from 'browlog';
import slackReporter from 'browlog/reporters/slack';

browlog({
  reporters: [
    slackReporter('<webhook_url>'),
  ]
});

Browlog will start to listen to any errors happening in your app. Hence, I would suggest to init browlog as early as possible.

Also please remember that this is only for client-side logger, if this code also runs in server (SSR / prerender), you should not init browlog when the code is running in server.

Reporters

You can import any existing reporters (or create your own), by importing from this path:

import reporter from 'browlog/reporters/<supported_reporter>';

List of currently supported reporters:

  1. Slack ('browlog/reporters/slack')
  2. Microsoft Teams ('browlog/reporters/teams')

Note: If you don't specify any reporters, browlog will be disabled automatically.

App Name

You can add app name to make distinct the logger between one and another. Follow the example below:

import browlog from 'browlog';
import teamsReporter from 'browlog/reporters/teams';

browlog({
  reporters: [
    teamsReporter('<webhook_url>', {
      appName: 'My App', // "appName" will not be combined with "Log" object.
      environment: 'staging' // Other keys will be combined with "Log" object
    }),
  ]
});

App name treatment is valid to all types of reporters.

Custom

You can, however, add your own custom reporter as such:

const customReporter = (log) => {
  // do anything
  // as long as you return a promise here.
};

...

browlog({
  reporters: [
    customReporter,
  ]
});

You can check what is a Log object from the typings:

interface Log {
  type: string; // event type, could be window:onerror, etc.
  referrer: string;
  userAgent: string;
  timestamp: number; // unix timestamp
  time: string; // humanized timestamp, Asia/Jakarta as timezone
  href: string;
  messages: string[];
}

Options

Below are available options for browlog initialization:

/**
 * An array of promises generated from fetch after chain process a log request.
 * 
 * Read more about it here:
 * https://github.com/josteph/browlog#reporters
 */
reporters: ((...data: any[]) => void)[];

/**
 * Prevent browlog from init & attaching event listeners.
 * 
 * You can call another `browlog.init()` again somewhere.
 */
disable?: boolean;

/**
 * An array of regex to filter out unnecessary errors from being logged.
 * 
 * For example:
 * 
 * `[/Message\: Script error\./, /Vue warn/, /Service worker/]`
 */
ignoreErrors?: RegExp[];

/**
 * Debounce threshold for the logger to be queued before sending them in parallel.
 * 
 * Default value is `2000` (in ms)
 */
threshold?: number;