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

agent-open-cli-http-util

v0.1.0

Published

Use OpenCLI Browser Bridge cookies with standards-compatible HTTP requests.

Readme

agent-open-cli-http-util

通过 OpenCLI Browser Bridge 读取浏览器现有登录态,并把匹配请求 URL 的 Cookie 注入标准 fetch 请求。

环境要求

  • Node.js 20 或更高版本
  • 已安装并运行 OpenCLI Browser Bridge
  • 对应 Chrome Profile 已登录目标站点

安装

npm install agent-open-cli-http-util

单次请求

import { openCliFetch } from 'agent-open-cli-http-util';

const response = await openCliFetch('https://example.com/api/profile', {
  headers: {
    accept: 'application/json',
  },
});

console.log(response.status, await response.json());

复用客户端

import { createOpenCliHttpClient } from 'agent-open-cli-http-util';

const client = createOpenCliHttpClient({
  session: 'my-agent',
});

const response = await client.fetch('https://example.com/api/items', {
  method: 'POST',
  headers: {
    'content-type': 'application/json',
  },
  body: JSON.stringify({ name: 'demo' }),
});

登录页面与请求地址不同

默认使用请求 URL 查询 Cookie。Cookie 为空时,工具会在后台打开该 URL 并重试一次。可以为单次请求指定不同的 Cookie 查询地址和登录页面:

const response = await client.fetch('https://api.example.com/data', {}, {
  cookieUrl: 'https://login.example.com/',
  navigateUrl: 'https://login.example.com/sign-in',
});

如果不希望自动打开页面:

const client = createOpenCliHttpClient({
  autoNavigate: false,
});

FormData

const form = new FormData();
form.append('name', 'demo');
form.append('file', new Blob(['hello']), 'hello.txt');

await client.fetch('https://example.com/api/upload', {
  method: 'POST',
  body: form,
});

不要手工设置 multipart Content-Type,Node.js 会自动生成 boundary。

阶段耗时

onStage 只报告阶段名和耗时,不包含 Cookie:

const client = createOpenCliHttpClient({
  onStage: ({ name, durationMs }) => {
    console.error(`${name}: ${durationMs} ms`);
  },
});

可能的阶段为 loadOpenClireadCookiesnavigatereadCookiesRetryrequest

企业 CA

访问使用企业证书的服务时,由调用方使用系统 CA 启动 Node.js:

node --use-system-ca app.mjs

这个包不会重启宿主进程,也不会关闭 TLS 校验。

安全约束

  • 只接受绝对 HTTP/HTTPS URL。
  • Cookie 仅注入请求,不通过 API、日志或错误信息返回。
  • Cookie 的域名、路径和安全属性由 Browser Bridge 按 cookieUrl 筛选。
  • 跨域重定向遵循 Node.js 原生 fetch 行为。