Skip to content

Opt-in per-client event throttling (#1)#8

Draft
tensiondriven wants to merge 1 commit into
masterfrom
feat/1-throttling
Draft

Opt-in per-client event throttling (#1)#8
tensiondriven wants to merge 1 commit into
masterfrom
feat/1-throttling

Conversation

@tensiondriven

Copy link
Copy Markdown
Contributor

Closes #1.

What

Opt-in, per-client event throttling for high-volume CDP domains. By default nothing changes — clients still get the raw firehose. A client opts in by passing eventThrottle to chrome-tap.attach:

{"id":2,"method":"chrome-tap.attach","params":{
  "tabId":123,
  "eventThrottle":{"Console.messageAdded":50,"Network.dataReceived":100,"*":200}
}}

Values are max events/sec per method ("*" is a wildcard; an explicit method overrides it). Events over the cap inside a 1s window are dropped newest-first.

Drops are never silent. Every 100ms the host emits a notice with per-method counts since the last flush:

{"type":"event","method":"chrome-tap.throttled","params":{"dropped":{"Console.messageAdded":312}}}

A throttled client whose WS send buffer backs up past 4MB also has its events dropped (and counted) until it drains — router-side backpressure so one slow consumer can't stall the host.

Approach / scope

The issue listed four candidate approaches. This implements the two that live entirely host-side and need no extension reload or Team-tier config:

  • Client-configurable throttle (the explicitly-spec'd eventThrottle on attach).
  • Router-side backpressure with a surfaced dropped count.

Extension-side ring buffering and array-batching were left out deliberately — batching would change the wire format (events become arrays) and touch the MV3 service worker; worth its own issue if the host-side limits prove insufficient.

Throttle state is per WS client, so throttling one client never affects another subscribed to the same tab. eventThrottle is stripped before commands are forwarded to the extension/CDP.

Files

  • host/throttle.jsClientThrottle (sliding window, wildcard, drop accounting).
  • host/router.js — applies throttle + backpressure in the event fan-out; flush timer for chrome-tap.throttled; strips eventThrottle on attach.
  • host/throttle.test.js — 11 tests via the built-in node:test runner (zero new deps).
  • host/package.json — adds npm test.
  • README.md — documents the opt-in throttle.

Verification

  • node --check clean on every host/*.js.
  • cd host && npm test → 11 passing, 0 failing.

No lint/typecheck tooling exists in the repo (vanilla CommonJS, no eslint/prettier/tsconfig), so syntax check + tests are the bar. No pre-existing warnings to baseline against.

🤖 Generated with Claude Code

Noisy CDP domains (Console.enable, Network.enable) can emit 100k+ events
that back up native messaging stdio and drown slow WS clients. Add an
opt-in throttle, configured per client via chrome-tap.attach:

  chrome-tap.attach { tabId, eventThrottle: { "Console.messageAdded": 50, "*": 200 } }

- host/throttle.js: ClientThrottle — sliding 1s window per method, "*"
  wildcard with explicit-method override, accumulates dropped counts.
- router.js: applies throttle + 4MB send-buffer backpressure in the event
  fan-out; flushes a chrome-tap.throttled notice (per-method dropped counts)
  every 100ms so loss is never silent. eventThrottle is stripped before
  forwarding to the extension/CDP.
- Default is unchanged: no config => raw firehose. Per-client, so one slow
  consumer never throttles others.
- Tests via node:test (zero deps); `npm test` in host/.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Event throttling for high-volume CDP domains (Console, Network, etc.)

1 participant