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

@bug-crusher/client-js

v1.0.4

Published

Capture console logs and fetch errors

Downloads

15

Readme

Description Awesome

BugCrusher is a tool for sending bug reports to your support. Users in your app can record bug with all the action and how it happens. Once they finish recording, they'll get two files. One file is a screen capture to make sure on which screen was user. Another file is a report with all the logs from console and reports that you created with BugCrusher API. The report can be open later by the developers to check the bug. It is recommended to encrypt this report so the end-user can't get sensitive data. Thanks for using this library 🙌 and happy hunting 🎯.

Installation

You can install using npm

npm install @bug-crusher/client-js

or yarn.

yarn add @bug-crusher/client-js

Examples

Creating client

When you create a client in options arguments using a key is recommended to encrypt sensitive data but it is not required.

import { createClient } from '@bug-crusher/client-js';

const client = createClient({
    key: process.env.CRYPTO_KEY,
    video: { mediaSource: 'screen' },
});

Start recording

If will start recording all the console logs and your reports. If the client is not created with video options it will start recording only reports and console logs.

client.startRecording();

Push report

It can push any data you want to an array. You can get this data with the function getReport or saveReport. Time is added by default and type as general for each report. You should push in options the type and set it like network or anything you like so you can easily find it. Console reports have type as console. Keep in mind you'll have to create a hook to your fetch function to push network report.

const url = 'https://some-super-long-url-and-bla-bla';

const fetchOptions = {
    method: 'GET',
    headers: {
        Authorization: 'some-jwt-token'
    }
};

const report = {
    reqUrl: url,
    reqOptions: fetchOptions,
    resHeaders: [],
    resRedirected: false,
    resStatus: 0,
    resStatusText: '',
    resType: '',
    resData: {},
    resError: {},
};

/**
 *Then hook to your fetch function like this
 */
fetch(url, fetchOptions)
    .then((response) => {
        response.headers.forEach((value, name) => {
            const header = { [name]: value };
            report.resHeaders.push(header);
        });

        report.resRedirected = response.redirected;
        report.resStatus = response.status;
        report.resStatusText = response.statusText;
        report.resType = response.type;

        return response.json()
    })
    .then((result) => {
        report.resData = result;
        bugCrusher.pushReport(report, { type: 'network' });
    })
    .catch(err =>{
        report.resError = err;
        bugCrusher.pushReport(report, { type: 'network'});
    });

Stop recording

Stops recording. Video, console logs, and report logs that you are pushing with the pushReport function.

client.stopRecording();

Whether recording is in progress

For example, in React app, you could check if the client started recording and then hide the modal.

if (!client.isRecording()) {
    return setModal(true);
}
setModal(false);

Save report to file

While you are saving the report you could name the file. It is not required to be named, it has a default name.

client.saveReport('filename');

Save screen recording to file

While you are saving the screen recording you could name the file. It is not required to be named, it has a default name.

client.saveVideo('filename');

📙 Functions

| Functions | Description | | --- | --- | | pushReport | It can push any data you want to an array. You can get this data with the function getReport or saveReport. Time is added by default and type as general for each report. You should push in options the type and set it like network or anything you like so you can easily find it. Console reports have type as console. Keep in mind you'll have to create a hook to your fetch function to push report with function pushReport. | | startRecording | It starts screen recording. Users have to choose which screen to record if it is supported by the browser. You'll start report recording too. | | stopRecording | It stops all the recording. It also prepares video files for saving on your local machine. | | getReport | It gets all the report history. It consists of an array of objects with properties time, type and data. | | saveReport | It saves the report file that consists of all the console logs and the report you created. It is recommended to use encryption. | | openReport | It opens the report, and if you are using encryption it will be decrypted. This can be added to your admin part of the app, you don't want to end-users see this report. | | saveVideo | It saves the screen recording to file. | | isRecording | Check is the app started recording. | | isHooked | Check is app hooked to console logs. |