Skip to content

Split BaseViewModel into a webview-free core and a browser-automation layer - #703

Merged
micahflee merged 2 commits into
mainfrom
issue-701-split-base-view-model
Sep 11, 2026
Merged

micahflee merged 2 commits into
mainfrom
issue-701-split-base-view-model

Conversation

@micahflee

Copy link
Copy Markdown
Member

Fixes #701.

BaseViewModel carried two unrelated responsibilities: one platform-agnostic, one about driving an embedded browser. Bluesky, which uses the AT Protocol directly, inherited the second and refused it — it left the webview null, so every automation method it inherited silently returned undefined instead of failing. #676 would have written Bluesky jobs against that.

What changed

BaseViewModel is now the core alone: account state and reload, logging, error reporting, pause and resume, power-monitor handling, translation. BrowserViewModel adds the webview lifecycle and the page-interaction helpers — loadURL/waitForURL, selector waiting, scripted clicks, mouseovers, scrolling, executeJavaScript. X and Facebook build on the browser layer; Bluesky builds on the core, so no automation method is reachable on it at all.

Error reporting splits along the same line. The core produces a complete report for a platform with no page to look at, and the browser layer fills in the page URL and a screenshot through a hook. Each platform now derives the label its report names the account by, instead of the core branching on account type, so adding a platform no longer means editing the core. Bluesky names no account, per docs/adr/0029-minimize-bluesky-diagnostics.md.

The webview seam moved into the platform config: usePlatformView starts a view model with a webview only when the platform declares it drives one, and offers webview props only to those platforms. Bluesky's view starts its view model through that seam like every other platform. Starting is still typed per platform — X and Facebook fail to compile if started without a webview, and a platform that declares it drives a browser but is handed none throws rather than half-starting.

The failures raised while driving a page move to their own module. They are ordinary errors with no webview in them; the core re-exports them for the automation-driven platforms that already import them from there.

Scope

This is a refactor: no user-visible behaviour changes on any platform. X and Facebook behaviour is unchanged and their existing tests pass untouched — each gains one new test covering the account label it now derives.

npm run lint is clean and the full suite passes (105 files, 1359 tests, no type errors).

Known follow-ups, not done here

  • The core re-exports TimeoutError / URLChangedError / InternetDownError as a compatibility path, because seven X test files import them from there and Split BaseViewModel into a webview-free core and a browser-automation layer #701 requires those tests pass unmodified. Rewriting those imports and dropping the shim is a separate change.
  • error() still emits x-submit-progress-${id} for every platform, and only XView listens. Pre-existing, and named in a comment rather than renamed, since renaming it is a behaviour change.

🤖 Generated with Claude Code

(This was written by an LLM.)

micahflee and others added 2 commits September 11, 2026 11:25
BaseViewModel carried two unrelated jobs: one platform-agnostic (account
state and reload, logging, error reporting, pause and resume, sleep and
wake, translation) and one about driving an embedded browser (the webview
lifecycle, navigation, selector waiting, scripted clicks and scrolling).
Bluesky, which uses the AT Protocol directly, inherited the second and
refused it: it left the webview null, so every automation method it
inherited silently returned undefined instead of failing.

BaseViewModel is now the core alone, and BrowserViewModel adds the
webview and the page-interaction helpers. X and Facebook build on the
browser layer; Bluesky builds on the core, so no automation method is
reachable on it at all. #676 can write Bluesky jobs against a base whose
every method works.

Error reporting keeps the whole report for a platform with no page to
look at. The page URL and the screenshot now come from a hook the
browser layer fills in, and each platform derives the label its report
names the account by, rather than the core branching on account type.
Bluesky names no account, per
docs/adr/0029-minimize-bluesky-diagnostics.md.

The webview seam moves into the platform config: usePlatformView starts
a view model with a webview only when the platform declares it drives
one, and offers webview props only to those platforms. Bluesky's view
starts its view model through that seam like every other platform.

The failures raised while driving a page move to their own module. They
are ordinary errors with no webview in them, and the core re-exports
them for the automation-driven platforms that already import them from
there.

X and Facebook behavior is unchanged and their existing tests pass
untouched; each gains one test covering the account label it now
derives. Fixes #701.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Starting a platform is typed per platform again. usePlatformView takes
whatever that platform's own init takes, so X and Facebook still fail to
compile if they are started without a webview, and Bluesky still takes
none. A platform that declares it drives a browser and is handed no
webview now throws instead of logging: half-starting a view model whose
every job needs a page is worse than stopping.

The list of automation methods a webview-free platform must not expose
lives in the test utilities, so the core's assertions and Bluesky's
cannot drift apart after a rename.

The core's doc no longer claims to be platform-agnostic, because error()
still emits X's progress-submit event for every platform. That is
pre-existing and named where it happens rather than fixed here.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@micahflee
micahflee merged commit b63e738 into main Sep 11, 2026
1 check passed
@micahflee
micahflee deleted the issue-701-split-base-view-model branch September 11, 2026 18:39
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.

Split BaseViewModel into a webview-free core and a browser-automation layer

1 participant