Skip to content

feat(grab): knobs:grab event and a grab send target - #117

Merged
mertbuilds merged 3 commits into
mainfrom
feat/grab-send
Nov 27, 2026
Merged

mertbuilds merged 3 commits into
mainfrom
feat/grab-send

Conversation

@mertbuilds

Copy link
Copy Markdown
Collaborator

Summary

  • Every grab fires one knobs:grab window event (detail: the grab payload) as the copy starts, on both paths (grab mode and grab()).
  • New mount option grabSend (and data-grab-send on the script tag): a URL gets each grab POSTed as { type: "knobs.grab", payload }, a function gets the payload. Only the page's own origin or http(s) on localhost, 127.0.0.1 and *.localhost are allowed. The clipboard copy always runs first; sends time out after 10 s.
  • Toast says "Copied · Sent" or "Send failed" only when a target is set; nothing changes without one.
  • Why: the local review server (review.localhost) wants grabs sent to it instead of pasted.

Proof

  • Browser run in an ego task space: a page with <script src="/index.global.js" data-grab-send="/grab">, ⇧G then a click on a button. The page listener got the event once; the local server logged one application/json POST with {"type":"knobs.grab","payload":{content, entries}}; the toast said "Copied · Sent".
  • bun test in packages/devknobs: 4716 pass, 0 fail (new tests: event once per grab on both paths, URL POST body, non-local and opaque-origin URLs refused with one warning, function target, failing and hanging targets still copy, failed copy toasts at once, URL and function send timeouts).
  • The hang test fails with the mode.ts fix stashed and passes with it; the URL timeout test fails without AbortSignal.timeout and passes with it.
  • bun run typecheck, bun run build, pnpm lint, pnpm format:check, pnpm --filter @knobs/web build and test (71 pass), extension typecheck and tests (82 pass).
  • Two code-reviewer rounds; all findings fixed (hang hid "Copy failed", opaque origin check, JSDoc, docs wording, missing fetch timeout test).

Weakened checks

None. One existing test ("toast says Sent") waited 3 microtask ticks; it now uses the 5-tick loop its neighbor tests use, same assertions.

Risk

Tier: normal. Area: grab send path (client-side POST to same-origin or localhost URLs only). Not released: CHANGELOG has it under Unreleased; ships with the next tested batch.

How to revert

Revert the merge commit. Nothing is released, so no npm or store rollback.

Test plan

  • Grab with no target: behavior and toasts unchanged
  • Grab with a URL target on a local page: one POST, "Copied · Sent"
  • Non-local URL target: refused with one console warning

@mertbuilds
mertbuilds merged commit c5bdf8d into main Nov 27, 2026
3 checks passed
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.

1 participant