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

weer

v0.0.6

Published

Web Extensions Error Reporter catches global errors, shows notifications and opens error reporter in one click

Downloads

24

Readme

Weer API Documentation

This file describes Weer API, for an introduction into Weer and for the most fresh API see GitHub repository.

Weer.Utils

File: weer-repo/src/src/utils.js
Objectives:

  1. Help in catching errors with weer.
  2. Help to write more robust code.

Utils.mandatory()

const foo = function foo(one = 'one', two = Utils.mandatory()) {
  /*...*/
};
foo('one'); // Throws error.
foo('one', 'two'); // No error.
foo('one', null); // No error.
foo('one', undefined); // Throws error (surprise).

Utils.throwIfError(error)

Throws first argument if it is == true.

const foo = function foo(cb) {
  /*...*/
  const error = new Error('oops');
  cb(error, result);
};
foo(Utils.throwIfError); // Throws Error('oops').

Utils.checkChromeError()

Checks chrome.runtime.lastError and returns new Error(message) or nothing.

chrome.runtime.openOptionsPage(
  () => {
    const err = Utils.checkChromeError(); // Error if no options page in `manifest.json`.
    /*...*/
  }
);

Utils.timeouted((...args) => {/*...*/})

Fixes context for thrown errors to that, which allows catching on global window.

chrome.runtime.openOptionsPage(Utils.timeouted((/*arg1, arg2, ...*/) => {

  throw new Error('I am catchable!');

}))

Utils.chromified((error, ...args) => {/*...*/})

Allows to use error-first callbacks with chrome apis. Also Utils.timeouts callback.

chrome.runtime.openOptionsPage(Utils.chromified((err, res1, res2) => {

  if (err) {
    throw err;
  }
  throw new Error('I am catchable!');

}))

Utils.getOrDie((...args) => {/*...*/})

Gets result of chrome API, throws error in case of error, passes result to callback otherwise.

chrome.runtime.openOptionsPage(Utils.getOrDie((res1, res2) => {

  throw new Error('I am catchable!');

}))

Utils.assert(valueToTest, errorMessage)

Poor man's assert.

Weer.ErrorCatchers

installListenersOn(configs, cb)

Installs error and unhandled rejections catchers on hostWindow object, in case of error calls handleErrorMessage({ to: 'error-reporter', payload: plainErrorEventObject }).

Configs

{
  hostWindow = window,
  nameForDebug = 'BG',
  handleErrorMessage,
};

Returns

uninstallListeners

Weer.GetNotifiersSingleton(configs)

Configs

{
 sendReports: {
    toEmail = '[email protected]',
    // In what language to display a template for the error reporting form.
    // Use only those languages that your support team may understand.
    inLanguages = ['en'],
  },
  onNotificationClick = defaultClickHandler,
  // Icons:
  extErrorIconUrl = 'https://rebrand.ly/ext-error',
  pacErrorIconUrl = 'https://rebrand.ly/pac-error',
  maskIconUrl = false,
};

onNotificationClick is a function (errorMessage, report) => {...}. Report looks like:

{
  payload: {
    filename: "chrome-extension://mddbgiefhigdgkeggceilkaoamkbnajl/pages/popup/dist/bundle.js",  
    colno: 13,
    lineno: 373,
    error: {
      message: "I'm a type error!",
      name: "TypeError",
      stack: "...",
    },
    message: "Uncaught TypeError: I'm a type error!",
    path: "[[object Window]]",
    type: "error",
  },
  errorType: "ext-error",
  extName: "PAC Kitchen",
  version: "0.0.0.1",
  userAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36",
  platform: "Linux x86_64",
}

Return Type

const noty = Weer.GetNotifiersSingleton(configs);
noty.switch('off'); // Switches off notifications.
noty.switch('off', 'pac-error'); // Switches off notifications for pac-errors.
noty.isOn('pac-error');
// To get a Map of `{ error-type: "description" }`:
noty.getErrorTypeToLabelMap();

Weer.install(configs)

configs are passed to Weer.GetNotifiersSingleton, see above.