Skip to content

fix(types): connect() returns a typed Page handle (v0.20.0) - #11

Merged
hamr0 merged 2 commits into
mainfrom
fix/connect-page-type
Aug 30, 2026
Merged

hamr0 merged 2 commits into
mainfrom
fix/connect-page-type

Conversation

@hamr0

@hamr0 hamr0 commented Aug 30, 2026

Copy link
Copy Markdown
Owner

Summary

connect() was typed Promise<object>, so TypeScript adopters could not dereference page.goto / page.snapshot / page.click / page.close off the returned handle without casting — the entire interactive surface was unusable from types. Relayed from a peer session that found it scanning the published type surface; the publish adopter gate missed it because its quickstart only dereferences browse()'s string, never the connect() handle.

Fix

  • Drop connect()'s @returns {Promise<object>} so tsc infers the shape structurally from the returned object literals; re-export it as a named Page type (Awaited<ReturnType<typeof connect>>) — no hand-maintained interface to drift.
  • Page is a union of the two engine shapes (Chromium/CDP, Firefox/BiDi). Shared interaction methods dereference directly; an engine-specific escape hatch (cdp/createTab/dialogLog on Chromium, bidi/context on Firefox) is reached by narrowing (if ('cdp' in page)). Union is sound where an intersection would falsely claim a page carries both engines' hatches.
  • The always-optional option params on snapshot() / type() / injectCookies() are typed optional (= {} defaults) with named, member-checked shapes (exported SnapshotOptions / TypeOptions / CookieOptions), so page.snapshot() compiles and snapshot({ mdoe: 'read' }) is now a compile error, not a silent no-op.
  • browse() → Promise<string> unchanged.

Behavior-preserving: each method reads its opts via ?., and cdpType already defaults opts = {}. The Firefox type() default even removes a latent !!typeOpts.clear deref-on-undefined crash.

Validation

  • Packed the tarball, installed into a clean strict / nodenext / skipLibCheck:false consumer, compiled a quickstart dereferencing the real page methods → green after, red before (mutation check: no Page export, cdp/createTab inaccessible). Valid options compile; typos red.
  • tsc --noEmit exit 0 · full suite 254/254 · /security clean · /code-review medium → 1 minor finding (weak option types), fixed.

Bumps to v0.20.0 (minor: new public type exports). The [0.20.0] CHANGELOG entry also carries the already-unreleased CI entries (publish gate, npm@11 pin, scratch de-track).

🤖 Generated with Claude Code

hamr0 and others added 2 commits August 30, 2026 20:48
connect()'s JSDoc @returns was Promise<object>, so TS adopters couldn't
dereference page.goto/snapshot/click/close off the handle without casting.
Drop the object annotation so tsc infers the shape structurally from the
returned object literals, and re-export it as a named `Page` type
(Awaited<ReturnType<typeof connect>>) — no hand-maintained interface to drift.

Page is a union of the two engine shapes (Chromium/CDP, Firefox/BiDi): shared
interaction methods dereference directly; an engine-specific escape hatch
(cdp/createTab/dialogLog on Chromium, bidi/context on Firefox) is reached by
narrowing (`if ('cdp' in page)`). The union is sound where an intersection
would falsely claim a page carries both engines' hatches.

Type the always-optional option params on snapshot()/type()/injectCookies()
optional (default = {}) so idiomatic page.snapshot() and page.type(ref, text)
compile, and give them named, member-checked shapes (exported SnapshotOptions/
TypeOptions/CookieOptions) so a typo like snapshot({ mdoe: 'read' }) is a
compile error, not a silent no-op. Behavior-preserving: each reads its opts via
?., and cdpType already defaults opts = {}.

Validated by packing the tarball and compiling a strict (nodenext,
skipLibCheck:false) consumer quickstart against it — green after, red before;
valid options compile and typos red. Unit 144/144, integration 110/110,
tsc --noEmit clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rp7uDDFyQ5qsWHHqDXFjHA
Bumps to 0.20.0 (minor: adds the public `Page`, `SnapshotOptions`,
`TypeOptions`, `CookieOptions` type exports). Dates the CHANGELOG [0.20.0],
which also carries the already-unreleased CI entries (adopter-usable-types
publish gate, npm@11 provenance pin, agent/IDE scratch de-track).

Documents the `Page` handle type in barebrowse.context.md (import + engine
escape-hatch narrowing). PRD/README untouched — no product capability changed
and README already claims types work out of the box (now true for connect()).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rp7uDDFyQ5qsWHHqDXFjHA
@hamr0
hamr0 merged commit 888f713 into main Aug 30, 2026
1 check passed
@hamr0
hamr0 deleted the fix/connect-page-type branch August 30, 2026 18:55
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