Repository navigation
fix(types): connect() returns a typed Page handle (v0.20.0) - #11
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
connect()was typedPromise<object>, so TypeScript adopters could not dereferencepage.goto/page.snapshot/page.click/page.closeoff 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 dereferencesbrowse()'s string, never theconnect()handle.Fix
connect()'s@returns {Promise<object>}so tsc infers the shape structurally from the returned object literals; re-export it as a namedPagetype (Awaited<ReturnType<typeof connect>>) — no hand-maintained interface to drift.Pageis a union of the two engine shapes (Chromium/CDP, Firefox/BiDi). Shared interaction methods dereference directly; an engine-specific escape hatch (cdp/createTab/dialogLogon Chromium,bidi/contexton Firefox) is reached by narrowing (if ('cdp' in page)). Union is sound where an intersection would falsely claim a page carries both engines' hatches.snapshot()/type()/injectCookies()are typed optional (= {}defaults) with named, member-checked shapes (exportedSnapshotOptions/TypeOptions/CookieOptions), sopage.snapshot()compiles andsnapshot({ mdoe: 'read' })is now a compile error, not a silent no-op.browse()→Promise<string>unchanged.Behavior-preserving: each method reads its opts via
?., andcdpTypealready defaultsopts = {}. The Firefoxtype()default even removes a latent!!typeOpts.clearderef-on-undefined crash.Validation
Pageexport,cdp/createTabinaccessible). Valid options compile; typos red.tsc --noEmitexit 0 · full suite 254/254 ·/securityclean ·/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