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

requests-hook

v0.0.4

Published

Hooking XMLHttpRequest and fetch in browser, only es6.

Readme

requests-hook

简介

【注意】当前该模块尚未开发完毕,当前版本仅实现了 proxy 模式中 fetchXMLHttpRequestonResponse 处理。

API 参考

本模块的 API 设计参考了 ajax-hook

开发背景

由于 ajax-hook 底层是基于 Object.defineProperty 实现的,这在与其他同类模块共用时容易导致兼容性问题。为了克服这一问题,我们开发了本模块。

技术优势

通过使用 Proxy 代理,本模块放弃了对低版本浏览器的支持,从而提供了更好的与其他模块的兼容性。Object.defineProperty 默认情况下只能被定义一次,如果页面或用户的浏览器插件中存在类似的 hook,则可能会导致出错或因覆盖而失效。而使用 Proxy 则避免了这些问题。

【尚未开发】同时本模块扩展了对 fetchsendBeacon的支持,使其可以拦截所有网络请求,而不仅仅是 XMLHttpRequest

使用

安装

  • NPM引入

    npm install requests-hook

一个简单示例:

import {proxy} from "requests-hook";

proxy({
    //请求发起前进入
    onRequest: (config, handler) => {
        console.log(config.url)
        handler.next(config);
    },
    //请求发生错误时进入,比如超时;注意,不包括http状态码错误,如404仍然会认为请求成功
    onError: (err, handler) => {
        console.log(err.type)
        handler.next(err)
    },
    //请求成功后进入
    onResponse: (response, handler) => {
        console.log(response.response)
        handler.next(response)
    }
})

现在,我们便拦截了浏览器中通过XMLHttpRequest发起的所有网络请求!在请求发起前,会先进入onRequest钩子,调用handler.next(config) 请求继续,如果请求成功,则会进入onResponse钩子,如果请求发生错误,则会进入onError 。我们可以更改回调钩子的第一个参数来修改修改数据。