Tracked by #713.
Background
src/webkit/client.ts is a central 1,316-line module that mixes protocol transport, target multiplexing, browser commands, DOM script templates, event adapters, and errors. This is maintainability risk for a core automation path.
Objective
Split WebKitClient internals into focused modules while preserving the public BrowserBackend-facing facade.
Scope
- Extract protocol transport without changing public methods.
- Extract DOM script builders used by browser commands.
- Extract typed event adapters.
- Keep
WebKitClient as compatibility facade during migration.
Target files and paths
src/webkit/client.ts
- new
src/webkit/protocol-transport.ts
- new
src/webkit/target-session.ts
- new
src/webkit/browser-commands.ts
- new
src/webkit/dom-scripts.ts
- new
src/webkit/events.ts
- new
src/webkit/errors.ts
tests/unit/webkit*.test.ts
Implementation steps
- Create error module and update imports.
- Extract pure DOM script builders with tests.
- Extract protocol send/pending-request handling behind an interface.
- Move target lifecycle state into a target session module.
- Keep facade methods and run existing tests after each extraction.
Acceptance criteria
Verification
npm run lint -- --quiet
- Relevant WebKit unit tests
npm run build:cli
- Manual smoke: navigate, screenshot, javascript, inspect against Safari simulator.
Dependencies / recommended order
Run after WebKit hot-path tests exist. Split into multiple PRs; do not attempt the full extraction in one PR.
Risks and cautions
- This is a refactor; behavior changes need separate issues.
- Avoid broad renames that make review difficult.
- Keep WebKit protocol constraints from
CLAUDE.md.
Non-goals
- Do not change tool names or schemas.
- Do not migrate to Playwright/CDP.
- Do not combine with HTTP security work.
Ambiguity reducers
- “Facade” means external imports can still use
WebKitClient from the same path until a deprecation plan exists.
- Each extraction PR must have a small, reviewable diff.
- Pure script builders should be testable without simulator.
Validity review
Proceed after higher-priority safety and speed issues. The work is valid because WebKitClient is a core change surface.
Implementation detail refinements
- Use adapter interfaces to avoid circular dependencies.
- Move tests with the code where practical.
- Track line-count reduction as a secondary metric, not the success criterion.
Verification checklist reinforcement
Tracked by #713.
Background
src/webkit/client.tsis a central 1,316-line module that mixes protocol transport, target multiplexing, browser commands, DOM script templates, event adapters, and errors. This is maintainability risk for a core automation path.Objective
Split WebKitClient internals into focused modules while preserving the public BrowserBackend-facing facade.
Scope
WebKitClientas compatibility facade during migration.Target files and paths
src/webkit/client.tssrc/webkit/protocol-transport.tssrc/webkit/target-session.tssrc/webkit/browser-commands.tssrc/webkit/dom-scripts.tssrc/webkit/events.tssrc/webkit/errors.tstests/unit/webkit*.test.tsImplementation steps
Acceptance criteria
WebKitClientconstructor and BrowserBackend methods remain compatible.client.tsis materially reduced without a behavior rewrite.Verification
npm run lint -- --quietnpm run build:cliDependencies / recommended order
Run after WebKit hot-path tests exist. Split into multiple PRs; do not attempt the full extraction in one PR.
Risks and cautions
CLAUDE.md.Non-goals
Ambiguity reducers
WebKitClientfrom the same path until a deprecation plan exists.Validity review
Proceed after higher-priority safety and speed issues. The work is valid because WebKitClient is a core change surface.
Implementation detail refinements
Verification checklist reinforcement