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

@hawk.so/javascript

v3.2.0

Published

JavaScript errors tracking for Hawk.so

Downloads

1,148

Readme

Hawk JavaScript Catcher

Hawk allows to track JavaScript and TypeScript errors in your applications.

Here is the Hawk Web client and here is the Documentation.

Installation

We recommend adding Hawk script to page above others to prevent missing any errors.

Install via NPM or Yarn

Install package

npm install @hawk.so/javascript --save
yarn add @hawk.so/javascript

Then import @hawk.so/javascript module to your code.

import HawkCatcher from '@hawk.so/javascript';

Load from CDN

Get the newest bundle path from @hawk.so/javascript — open site and get the link to latest distributed JS bundle.

Then require this script on your site.

<script src="..." async></script>

Usage

Get an Integration Token

First of all, you should register an account on hawk.so.

Then create a Workspace and a Project in there. You'll get an Integration Token.

Initialize Catcher

Create HawkCatcher class instance when script will be ready and pass your Integration Token:

const hawk = new HawkCatcher({token: 'INTEGRATION_TOKEN'});

// or

const hawk = new HawkCatcher('INTEGRATION_TOKEN');

Alternately, add onload="const hawk = new HawkCatcher({token: 'INTEGRATION_TOKEN'})" attribute to the <script> tag.

<script src="https://cdn.rawgit.com/codex-team/hawk.javascript/master/hawk.js" onload="const hawk = new HawkCatcher({token: 'INTEGRATION_TOKEN'})"></script>

Initialization settings:

| name | type | required | description | | -- | -- | -- | -- | | token | string | required | Your project's Integration Token | | release | string/number | optional | Unique identifier of the release. Used for source map consuming (see below) | | user | {id: string, name?: string, image?: string, url?: string} | optional | Current authenticated user | | context | object | optional | Any data you want to pass with every message. Has limitation of length. | | vue | Vue constructor | optional | Pass Vue constructor to set up the Vue integration | | disableGlobalErrorsHandling | boolean | optional | Do not initialize global errors handling | | disableVueErrorHandler | boolean | optional | Do not initialize Vue errors handling | | beforeSend | function(event) => event | optional | This Method allows you to filter any data you don't want sending to Hawk |

Other available initial settings are described at the type definition.

Usage in React project

You can use the JavaScript catcher in your React project. Create the Hawk Catcher instance in a index.js file of your project.

Manual sending

You can send errors or other messages to the Hawk manually, for example at your catch blocks or any debug conditions.

Use the .send(message, context) method for that. This method accepts the message of type Error or string as the first parameter. The second parameter is optional, it allows passing any additional data with the event. If you specify the context with the HawkCatcher constructor, it will be merged with the context passed to the send method.

// init Hawk Catcher instance
const hawk = new HawkCatcher({token: 'INTEGRATION_TOKEN'});

// somewhere in try-catch block or other custom place
hawk.send(new Error('Something went wrong'), {
  myOwnDebugInfo: '1234'
});

Source maps consuming

If your bundle is minified, it is useful to pass source-map files to the Hawk. After that you will see beautiful original source code lines in Hawk Garage instead of minified code.

To enable source map consuming you should do two things:

  • Send the source map and the release identifier to the Hawk after you build a new version of the script. For example with the Hawk Webpack Plugin or with cURL request.
  • Pass the release identifier to the Hawk Catcher using release option.

Testing and server responses

To make sure that Hawk is working right, call test() method from HawkCatcher class instance in browser's console. test() method sends fake error to server. Then, open Hawk and find a test event at the Project's page.

Sensitive data filtering

You can filter any data that you don't want to send to Hawk. Use the beforeSend() hook for that reason.

window.hawk = new HawkCatcher({
  token: 'INTEGRATION TOKEN',
  beforeSend(event){
    if (event.user && event.user.name){
      delete event.user.name;
    }

    return event;
  }
})

Dismiss error

You can use the beforeSend() hook to prevent sending a particular event. Return false for that.

Integrate to Vue application

Vue apps have their own error handler, so if you want to catcher errors thrown inside Vue components, you should set up a Vue integration.

Pass the Vue constructor with the initial settings:

import Vue from 'vue';

const hawk = new HawkCatcher({
  token: 'INTEGRATION_TOKEN',
  vue: Vue // the Vue constructor you tweak
});

or pass it any moment after Hawk Catcher was instantiated:

import Vue from 'vue';

const hawk = new HawkCatcher({
  token: 'INTEGRATION_TOKEN',
});

hawk.connectVue(Vue)