Repository navigation
Split BaseViewModel into a webview-free core and a browser-automation layer - #703
Merged
Merged
Conversation
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>
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.
Fixes #701.
BaseViewModelcarried 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 returnedundefinedinstead of failing. #676 would have written Bluesky jobs against that.What changed
BaseViewModelis now the core alone: account state and reload, logging, error reporting, pause and resume, power-monitor handling, translation.BrowserViewModeladds 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:
usePlatformViewstarts 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 lintis clean and the full suite passes (105 files, 1359 tests, no type errors).Known follow-ups, not done here
TimeoutError/URLChangedError/InternetDownErroras 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 emitsx-submit-progress-${id}for every platform, and onlyXViewlistens. 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.)