fix(browser-control): bind the daemon on the main thread so sessions can start - #236
Open
SandroHub013 wants to merge 1 commit into
Open
fix(browser-control): bind the daemon on the main thread so sessions can start#236SandroHub013 wants to merge 1 commit into
SandroHub013 wants to merge 1 commit into
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
|
lgtm |
Collaborator
Author
|
/nikcli review this |
|
Unable to connect. Is the computer able to access the url? |
Owner
|
| Detail | Value |
|---|---|
| Failed step | Unknown step |
| Autofix status | ⏭️ Autofix skipped |
| Run | View full logs |
Failure Summary
(no summary available)
Please inspect the full Actions logs for complete output. Do not share this comment publicly — it may contain redacted paths.
…can start Bun.WebView's chrome backend - the backend everywhere except macOS - throws "only available on the main thread" when constructed off the main thread, and it throws at construction, so connecting to a running Chrome over a DevTools URL does not dodge it either. The compiled binary hosts the daemon in-process, and nikcli runs sessions on a worker thread, so that daemon bound its socket on a worker. It answered `list` (no view) and failed every `start` (which creates one). macOS was unaffected: it defaults to the webkit backend. The daemon now refuses to host on a worker and delegates binding to the host's main thread via setMainThreadDaemonHost(); the worker then talks to it over the same socket as any other client. nikcli wires that through the RPC channel the TUI worker already has. createWebView() also names the constraint now, instead of surfacing Bun's message with no caller and no fix in it. Fixes #235
SandroHub013
force-pushed
the
fix/browser-control-bun-webview
branch
from
August 21, 2026 00:02
e842b81 to
6efa91c
Compare
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.
Issue for this PR
Closes #235
Type of change
What does this PR do?
Bun.WebView's chrome backend — the backend on every platform except macOS — throwsBun.WebView with backend "chrome" is only available on the main threadwhen it is constructed offthe main thread. It throws at construction, so pointing it at an already-running Chrome through a
DevTools URL does not avoid it either.
The compiled binary hosts the browser-control daemon in-process, and nikcli runs sessions on a
worker thread, so that daemon bound its socket on a worker.
listworked because it creates noview; every
startfailed because it creates one. macOS was unaffected — it defaults to thewebkitbackend — which is why the report was Windows-only.The daemon no longer hosts itself on a worker. It delegates binding to the host's main thread via
setMainThreadDaemonHost(), and the worker then speaks to it over the same socket as any otherclient, so views are created on a thread that is allowed to have them. nikcli registers that hook
over the RPC channel the TUI worker already has. With no host registered,
ensureDaemonnow failswith a message naming the constraint instead of binding a daemon that cannot start a session.
createWebView()carries the same check, so any other caller gets an error with a fix in it ratherthan Bun's bare message.
How did you verify your code works?
First reproduced it, on Windows 11 / Bun 1.4.0, by hosting the daemon on a worker and calling
start:Then, with hosting delegated to the main thread and the session driven from a worker through the
same
Rpcutil the nikcli wiring uses:bun testinpackages/browser-control: 10 pass, including the newtest/worker-hosting.test.ts,which covers the hosting rule and drives a main-thread-hosted daemon from a worker
bun typecheckat the repo root: 35/35 packagesbun src/cli.ts start --url https://example.com --viewport 1024x768, pluslistandshutdown,behave as before — the CLI spawns its own daemon process, which was always on a main thread
script/build.ts --single) and confirmed it boots. Its TUIsmoke fails locally with
EPERM: mkdirunder the harness's synthetic HOME, but a binary builtfrom
live-mainin the same tree fails identically, so that is a local build issue and not thischange.
To confirm by hand: run
startfrom a compiled binary's TUI on Windows or Linux. It returned theWebView error before and returns session info now.
Screenshots / recordings
Not a UI change.
Checklist
Note for reviewers
The nikcli half touches the TUI worker/thread wiring (7 and 11 lines). If the delegation hook
belongs somewhere other than the existing
Rpc.emitchannel, say so and I will move it.