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

@c0b41/brave-this

v0.6.0

Published

Unofficial Brave Search scraper with debug artifact capture.

Readme

brave-this

Unofficial Brave Search scraper. Performs searches against search.brave.com, parses the embedded SvelteKit JSON payload, and returns structured results (organic, knowledge graph, news, videos, dictionary, …).

Install

pnpm add @c0b41/brave-this

Search

import { search } from '@c0b41/brave-this'

const results = await search({
  query: 'latest tech news',
  options: {
    safe: 'moderate',
    lang: 'en-US',
    page: 0,
    mobile: false,
  },
})

console.log(results.results) // organic
console.log(results.knowledges) // knowledge graph
console.log(results.news)
console.log(results.didYouMean)

Search params

type SearchParams = {
  query: string
  options?: {
    safe?: 'off' | 'moderate' | 'strict' // → ?safe=
    lang?: string // → ?search_lang= (e.g. 'en-US')
    page?: number // 0-indexed; → ?offset=page*10
    mobile?: boolean // picks from the mobile UA pool
    userAgent?: string // explicit UA; overrides `mobile` and the pool
    headers?: Headers // custom headers; merged over the defaults
    debugDir?: string // per-request debug artifact directory
  }
}

User agent

Three ways to control the outgoing user-agent header (priority top → bottom):

| Source | Effect | | ----------------------------------- | ------------------------------------------------------------------------------ | | options.userAgent | Explicit UA string. Used for both the HTTP header and the TLS fingerprint. | | options.headers with user-agent | Same as above, but set through the header bag. | | options.mobile | Picks a random UA from the mobile pool instead of the desktop pool. | | (unset) | Picks a random UA from the desktop pool. |

Examples:

// Random desktop UA (default)
await search({ query: 'katy perry' })

// Random mobile UA
await search({ query: 'katy perry', options: { mobile: true } })

// Pinned UA — deterministic requests, stable TLS fingerprint
await search({
  query: 'katy perry',
  options: {
    userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
  },
})

// Pinned UA + extra headers
await search({
  query: 'katy perry',
  options: {
    userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
    headers: new Headers({
      'accept-language': 'tr-TR,tr;q=0.9,en;q=0.8',
    }),
  },
})

Custom headers

options.headers accepts either a Headers instance or a plain Record<string, string>. Values are merged on top of the defaults, so you can override any single header without having to rebuild the whole bag:

await search({
  query: 'katy perry',
  options: {
    headers: {
      'accept-language': 'de-DE,de;q=0.9',
      'sec-ch-ua-platform': '"Linux"',
    },
  },
})

Result shape

type BraveSearchResult = {
  results: OrganicResult[] | null
  knowledges: ParsedKnowledgeGraphData | null
  news: NewsItem[] | null
  videos: Video[] | null
  weather: WeatherData | null
  time: TimeData | null
  location: LocationData | null
  dictionary: DictionaryData | null
  translation: TranslationData | null
  converters: ConversionData | null
  didYouMean: DidYouMeanData | null
  relatedqueries: RelatedQueriesData | null
  discussions: Discussion[] | null
}

OrganicResult

type OrganicResult = {
  title: string
  description: string
  url: string
  favicons: {
    high_res: string
    low_res: string
  }
  /** Human-readable age string (e.g. "2 hours ago"). Optional. */
  age?: string
  /** Sitelinks surfaced under the snippet (Wikipedia's "Life and career", …). Optional. */
  sitelinks?: { title: string; url: string }[]
}

ParsedKnowledgeGraphData

type ParsedKnowledgeGraphData = {
  type: string | null
  title: string | null
  description: string[]
  url: string | null
  metadata: { title: string; value: string }[]
  ratings: { name: string; rating: string }[]
  available_on: string[]
  images: KnowledgeGraphImage[]
  links: { name: string; url: string; icon: string }[]
  /** Infobox action tabs ("Songs", "Albums", "Movies", …). Always present. */
  actions: string[]
}

type KnowledgeGraphImage = {
  url: string
  alt?: string
  original?: string
  click_url?: string
  logo?: boolean
  source: string | null
}

Debugging

Everything is opt-in through environment variables.

| Variable | Effect | | ------------------------ | --------------------------------------------------------------------------------------------------- | | BRAVE_OUTPUT=1 | Write per-request artifacts (page.html, payload.js, payload.json, parsed.json, meta.json) | | BRAVE_OUTPUT_DIR=/path | Root directory for artifacts (default: ./data/debug) | | DEBUG=brave:* | All internal logs (engine, http, artifacts, data, errors) | | DEBUG=brave:engine | Engine orchestration only | | DEBUG=brave:http | HTTP layer only (headers, TLS, status) | | DEBUG=brave:data | Payload extraction only | | DEBUG=brave:artifacts | File-write layer only |

Each request produces a self-contained directory:

data/debug/2025-01-15T10-30-00-000Z_latest-tech-news_a1b2c3/
  page.html      # raw HTML from Brave
  payload.js     # extracted <script> content
  payload.json   # parsed RootObject (after Function evaluation)
  parsed.json    # final BraveSearchResult
  meta.json      # query, url, options, timestamp

Example

BRAVE_OUTPUT=1 BRAVE_OUTPUT_DIR=/tmp/brave DEBUG=brave:* node script.js

Per-request override

await search({
  query: 'katy perry',
  options: { debugDir: '/tmp/brave/katy-perry' },
})

Windows cmd.exe / PowerShell

VAR=value command is POSIX shell syntax. On Windows:

cmd.exe:

set BRAVE_OUTPUT=1
set DEBUG=brave:*
node script.js

PowerShell:

$env:BRAVE_OUTPUT='1'; $env:DEBUG='brave:*'; node script.js

cross-env (recommended for scripts in package.json):

"scripts": {
  "debug": "cross-env BRAVE_OUTPUT=1 DEBUG=brave:* node ./examples/index.js"
}

Then pnpm debug works identically on Windows, macOS, and Linux.

How it works

  1. BraveEngine.search() builds the URL (q, safe, search_lang, offset) and calls fetchHTML() with a full browser-like header set.
  2. fetchHTML() uses undici with an https-tls connector keyed on the selected user agent, so the TLS fingerprint matches the UA.
  3. extractJsData() finds the SvelteKit data: [...] block in the returned HTML, evaluates it as JavaScript (Brave's own payload — no user input is ever evaluated), and returns the RootObject.
  4. The 13 parsers walk that object and populate BraveSearchResult.

Errors

All errors thrown by the public API are SearchError instances with name, message, info, date, and version properties:

try {
  await search({ query: '' })
} catch (err) {
  if (err instanceof SearchError) {
    console.error(err.info) // { query: '' }
  }
}