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

@uwx/gm-fetch

v2.0.4

Published

The global `fetch` function is an easier way to make web requests and handle responses than using an XMLHttpRequest. This implementation uses GM_xmlhttpRequest as the underlying implementation, allowing user scripts to make cross-domain requests using the

Readme

GM_xmlhttpRequest powered implementation of window.fetch

The global fetch function is an easier way to make web requests and handle responses than using an XMLHttpRequest. This implementation uses GM_xmlhttpRequest as the underlying implementation, allowing user scripts to make cross-domain requests using the fetch API.

GM_fetch.ts differs from upstream GM_fetch by being rewritten in TypeScript and featuring a more consistent API. GM_fetch is based on GitHub's fetch polyfill.

Compatibility

  • GM_fetch.ts uses the legacy GM_xmlhttpRequest API as opposed to GreaseMonkey 4.0's GM.xmlHttpRequest for compatibility with a wider variety of userscript engines. As such, while it is compatible with TamperMonkey, ViolentMonkey, Scriptish, and legacy GreaseMonkey, it is unlikely to work on GreaseMonkey 4.0.
  • The default UTF-8 TextDecoder encoding is used for decoding response ArrayBuffer instances, with the exception of Response.text().
  • Response.text() is untested.
  • Body.formData() is unsupported for response bodies.
  • request.credentials: 'include' isn't explicitly implemented.

Installation

For regular userscripts, without any type of module bundler, you can add an @require clause to your script's header pointing to dist/GM_fetch.js. This is a UMD file that will adapt to either RequireJS, AMD, or Webpack, or export a GM_fetch variable to the current scope. The Headers, Request, and Response classes are only publicly visible if a module loader is used.

// @grant    GM_xmlhttpRequest
// @require  https://raw.githubusercontent.com/uwx/GM_fetch.ts/master/dist/GM_fetch.js

Note: This always links to the most up-to-date version, which may introduce breaking changes. Pinning to a commit, or self-hosting, is recommended.

Alternatively, for TypeScript projects, you can copy all the files in src to your project directly, and import ./GM_fetch.ts.

Usage

The fetch function supports the GET, HEAD and POST HTTP methods, as with GM_xmlhttpRequest. Here are some examples.

HTML

fetch('/users.html')
  .then(res => res.text())
  .then(body => document.body.innerHTML = body);

JSON

fetch('/users.json')
  .then(res => res.json())
  .then(json => console.log('parsed json', json)
  .catch(err => console.error('parsing failed', err);

Response metadata

fetch('/users.json').then(response => {
  console.log(response.headers.get('Content-Type'));
  console.log(response.headers.get('Date'));
  console.log(response.status);
  console.log(response.statusText);
});

Post form

var form = document.querySelector('form')

fetch('/query', {
  method: 'post',
  body: new FormData(form)
});

Post JSON

fetch('/users', {
  method: 'post',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    name: 'Hubot',
    login: 'hubot',
  })
});

File upload

const input = document.querySelector('input[type="file"]')

const form = new FormData()
form.append('file', input.files[0])
form.append('user', 'hubot')

fetch('/avatars', {
  method: 'post',
  body: form
});

Success and error handlers

This causes fetch to behave like jQuery's $.ajax by rejecting the Promise on HTTP failure status codes like 404, 500, etc. The response Promise is resolved only on successful, 200 level, status codes.

function status(response) {
  if (response.ok) {
    return response;
  }
  throw new Error(response.statusText);
}

fetch('/users')
  .then(status)
  .then(res => res.json())
  .then(json => console.log('request succeeded with json response', json))
  .catch(err => console.log('request failed', err));