Tracked by #713.
Background
OpenSafari’s core work is WebKit Remote Debugging Protocol automation. Navigation, screenshot, DOM inspection, and evaluate are frequent paths, so reducing protocol round trips improves real user speed.
Objective
Add fast value-return evaluation and reduce redundant WebKit RPCs in navigation and screenshot flows.
Scope
- Add a value-oriented evaluate helper for non-promise primitive/object results.
- Batch post-navigation state reads.
- Cache enabled protocol domains per target.
- Reduce fixed sleeps where event or state checks are sufficient.
Target files and paths
src/webkit/client.ts
- new
src/webkit/evaluate.ts or extracted command module if refactoring begins
tests/unit/webkit*.test.ts or new tests for evaluation/navigation helpers
Implementation steps
- Introduce
evaluateValue<T> or an equivalent option using returnByValue: true.
- Update screenshot viewport query to use the fast path.
- Combine final URL, readyState, and status reads into one evaluation.
- Track enabled domains to avoid duplicate
Page.enable and Network.enable calls.
- Add tests using mocked send calls to assert lower RPC count.
Acceptance criteria
Verification
npm run lint -- --quiet
- Targeted WebKit client unit tests
- Manual smoke on macOS simulator: navigate, screenshot, read_page still work.
Dependencies / recommended order
Can run after proxy readiness work or independently if tests use mocks. Prefer before large WebKitClient refactor so performance behavior is captured by tests.
Risks and cautions
- Do not break promise-returning evaluation semantics.
- Do not use Chrome CDP APIs; preserve WebKit protocol constraints from
CLAUDE.md.
- Do not remove existing error handling paths.
Non-goals
- Do not rewrite all
WebKitClient responsibilities in this issue.
- Do not introduce Playwright/CDP abstractions.
- Do not change screenshot protocol from
Page.snapshotRect.
Ambiguity reducers
- “Fast path” applies only when callers expect serializable values.
- The existing generic
evaluate remains available for promise/objectId cases.
- RPC count assertions should focus on specific helper calls, not entire workflows with simulator variability.
Validity review
Proceed. It is central to the automation product because most user-visible actions pass through WebKit RPCs.
Implementation detail refinements
- Add helper first, then migrate one or two hot paths per PR.
- Prefer typed return helpers over adding more
any casts.
- Use WebKit event support only after confirming protocol availability in tests or live smoke.
Verification checklist reinforcement
Tracked by #713.
Background
OpenSafari’s core work is WebKit Remote Debugging Protocol automation. Navigation, screenshot, DOM inspection, and evaluate are frequent paths, so reducing protocol round trips improves real user speed.
Objective
Add fast value-return evaluation and reduce redundant WebKit RPCs in navigation and screenshot flows.
Scope
Target files and paths
src/webkit/client.tssrc/webkit/evaluate.tsor extracted command module if refactoring beginstests/unit/webkit*.test.tsor new tests for evaluation/navigation helpersImplementation steps
evaluateValue<T>or an equivalent option usingreturnByValue: true.Page.enableandNetwork.enablecalls.Acceptance criteria
evaluatebehavior remains compatible.Verification
npm run lint -- --quietDependencies / recommended order
Can run after proxy readiness work or independently if tests use mocks. Prefer before large WebKitClient refactor so performance behavior is captured by tests.
Risks and cautions
CLAUDE.md.Non-goals
WebKitClientresponsibilities in this issue.Page.snapshotRect.Ambiguity reducers
evaluateremains available for promise/objectId cases.Validity review
Proceed. It is central to the automation product because most user-visible actions pass through WebKit RPCs.
Implementation detail refinements
anycasts.Verification checklist reinforcement