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

react-native-cpr-logger

v0.0.7

Published

An HTTP traffic monitor for React Native with zero dependencies

Downloads

24

Readme

react-native-cpr-logger GitHub stars

CI Dependencies npm npm bundle size npm downloads License

An HTTP traffic monitor for React Native including in app interface.

An alternative to Wormholy but for both iOS and Android and with zero native dependencies.

If this project has helped you out, please support us with a star 🌟.

Features

  • Log networks requests on iOS and Android
  • View network requests made with in app viewer
  • Debug network requests on release builds
  • Individually view request/response headers and body
  • Copy or share headers, body or full request
  • Share cURL representation of request
  • Zero native or JavaScript dependencies
  • Built in TypeScript definitions
  • Extracts GraphQL operation name
  • Export all logs in HAR format

Screenshots

iOS

Android

Setup

Install

yarn add react-native-cpr-logger

or

npm install --save react-native-cpr-logger

Start Logging

Call startNetworkLogging in your apps entry point to log every request, or call it on a button press to manually trigger it.

import { startNetworkLogging } from 'react-native-cpr-logger';

startNetworkLogging();
AppRegistry.registerComponent('App', () => App);

Display Requests and Responses

import NetworkLogger from 'react-native-cpr-logger';

const MyScreen = () => <NetworkLogger />;

Themes

You can change between the dark and light theme by passing the theme prop with "dark" or "light".

import NetworkLogger from 'react-native-cpr-logger';

const MyScreen = () => <NetworkLogger theme="dark" />;

If preferred you can also override the theme entirely by passing in a theme object.

Note: breaking theme changes are not guaranteed to follow semver for updates

import NetworkLogger from 'react-native-cpr-logger';

const MyScreen = () => (
  <NetworkLogger
    theme={{
      colors: {
        background: 'red',
      },
    }}
  />
);

Logging options

Max Requests

You can configure the max number of requests stored on the device using by calling startNetworkLogging with the maxRequests option. The default is 500.

startNetworkLogging({ maxRequests: 500 });

Ignored Hosts

You can configure hosts that should be ignored by calling startNetworkLogging with the ignoredHosts option.

startNetworkLogging({ ignoredHosts: ['test.example.com'] });

Ignored Urls

You can configure urls that should be ignored by calling startNetworkLogging with the ignoredUrls option.

startNetworkLogging({ ignoredUrls: ['https://test.example.com/page'] });

Ignored Patterns

You can configure url patterns, including methods that should be ignored by calling startNetworkLogging with the ignoredPatterns option.

startNetworkLogging({
  ignoredPatterns: [/^GET http:\/\/test\.example\.com\/pages\/.*$/],
});

The pattern to match with is the method followed by the url, e.g. GET http://example.com/test so you can use the pattern to match anything, e.g. ignoring all HEAD requests.

startNetworkLogging({
  // Ignore all HEAD requests
  ignoredPatterns: [/^HEAD /],
});

Sorting

Set the sort order of requests. Options are asc or desc, default is desc (most recent at the top).

import NetworkLogger from 'react-native-cpr-logger';

const MyScreen = () => <NetworkLogger sort="asc" />;

Max Rows

Set the maximum number of rows to display in the list to improve rendering. Default is same as request limit.

import NetworkLogger from 'react-native-cpr-logger';

const MyScreen = () => <NetworkLogger maxRows={100} />;

Compact Rows

Make the rows smaller to fit more on the screen.

import NetworkLogger from 'react-native-cpr-logger';

const MyScreen = () => <NetworkLogger compact />;

Force Enable

If you are running another network logging interceptor, e.g. Reactotron, the logger will not start as only one can be run at once. You can override this behaviour and force the logger to start by using the forceEnable option.

startNetworkLogging({ forceEnable: true });

Integrate with existing navigation

Use your existing back button (e.g. in your navigation header) to navigate within the network logger.

import NetworkLogger, { getBackHandler } from 'react-native-cpr-logger';

const navigation = useNavigation();
const onBack = getBackHandler(navigation.goBack);

const MyScreen = () => (
  <Screen onBackPressed={onBack}>
    <NetworkLogger />
  </Screen>
);

Example App

To test the example app, after cloning the repo, install the required dependencies by running:

yarn bootstrap

Then start the example app by running:

yarn example start

You should then be able to open the expo server at http://localhost:3000/ and launch the app on iOS or Android.

For more setup and development details, see Contributing.

Why

Network requests can be debugged using tools such as React Native Debugger, however this requires both a debug build of the app and the debugger to be enabled. This library can be built with you app and usable by anyone using your app to see network issues and report them back to developers.

As the library is very small you can safely bundle it with the production version of your app and put it behind a flag, or have a separate testing build of the app which has the network logger enabled.

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.