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 🙏

© 2026 – Pkg Stats / Ryan Hefner

cors-manager

v1.0.6

Published

Manage the policy of CORS for allowed origins

Downloads

749

Readme

cors-manager

cors-manager is a permission manager for requesting with force-CORS.

It consists of:

  • a userscript runtime that performs privileged requests via GM.xmlHttpRequest
  • a typescript library with fetch()-like API, by talking to the userscript through window.postMessage

Install Userscript

Getting Started

npm install cors-manager
import {
  initialize,
  isInitialized,
  checkStatus,
  requestPermission,
  fetchCors,
} from 'cors-manager';

// initialize(): Promise<boolean>
window.addEventListener('load', () => initialize(), { once: true });

// When the initialize() is finished
if (isInitialized()) {
  const targetUrl = 'https://api.example.com/data';

  // requestPermission(url): Promise<boolean>
  const granted = await requestPermission(targetUrl);
  if (!granted) {
    throw new Error('Permission denied by user.');
  }
}

// When the request is needed
const response = await fetchCors(targetUrl, {
  method: 'GET',
  headers: {
    Accept: 'application/json',
  },
});

const json = await response.json();
console.log(json);

Requirements

  • A userscript manager such as Tampermonkey/Violentmonkey
  • The cors-manager userscript should be installed and active

Permission Model

  1. First-time site trust: The user must allow to enable the manager.
  2. First request to a target origin: The user must allow that target.
  3. Allowed target origins are persisted per current site origin.

The user can revoke everything from the "Revoke Permissions" menu in userscript.

API

initialize(): Promise<boolean>

Starts the handshake with the userscript.

  • Returns true when the current site is trusted and CORS manager is active
  • Returns false if the handshake fails, times out, or the site is not approved

isInitialized(): boolean

Returns whether the site is approved by initialize().

checkStatus(url: RequestInfo | URL): Promise<boolean>

Checks whether the target origin is currently allowed.

  • Returns true when the target origin is already allowed
  • Returns false when not allowed, denied, or when no reply is received in time

requestPermission(url: RequestInfo | URL): Promise<boolean>

Requests permission for the target origin.

  • Returns true when the origin is approved
  • Returns false when denied or when no reply is received in time

fetchCors(url: RequestInfo | URL, init?: RequestInit): Promise<Response>

Sends a request through the userscript channel.

  • Throws if no response is received in time
  • Throws if the userscript rejects the request (for example: denied origin)
  • Returns a normal Response object on success

Acknowledgements