Skip to content

feat(extension): make the local daemon port configurable in the popup - #175

Open
shnpd wants to merge 4 commits into
mainfrom
feat/configurable-daemon-port
Open

feat(extension): make the local daemon port configurable in the popup#175
shnpd wants to merge 4 commits into
mainfrom
feat/configurable-daemon-port

Conversation

@shnpd

@shnpd shnpd commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

摘要

fix #114
扩展原先写死连接 ws://127.0.0.1:52800。本 PR 让用户在 popup 里配置本机 daemon 端口,写入 chrome.storage.local 后 background 自动改 WebSocket URL 并重连。默认端口仍为 52800

未连接时不再展示 [WSTransport] ... 这类技术错误,改为提示确认 daemon 已启动且端口一致;连接开关在未连接时显示为关闭。

改动说明

  • Popup 新增「连接端口」输入,blur / Enter / 关闭弹窗时提交;非法端口只提示、不写入。
  • 端口走 chrome.storage.localbsk_daemon_port),不再使用未接线的 set_port 消息。
  • Background 启动时读取已存端口;监听 storage 变化后 setUrl + disconnect/connect。
  • WSTransport 支持运行时更换 URL(不自动重连)。
  • 隐私政策、架构文档、中英文案同步更新。

ui展示

企业微信20260902-192153@2x image

测试

  • 默认端口 52800 能正常连上 daemon
  • popup 改成有效端口(如 53200)后,扩展会重连到新端口
  • 输入非法端口(abc / 0 / 65536)显示错误,且不写入 storage
  • 清空输入后回落到默认端口
  • 连接开关关闭时改端口,不会强制重连
  • daemon 未启动或端口不一致时,显示「无法连接…」,不显示原始 transport 错误
  • 重新打开 popup,端口输入框显示上次保存的值

shnpd and others added 2 commits September 2, 2026 18:56
The extension was hardwired to 52800; persist a custom loopback port and reconnect when it changes so users can match a non-default daemon.

Co-authored-by: Cursor <cursoragent@cursor.com>
The field was too short to read; grow its height without widening the card.

Co-authored-by: Cursor <cursoragent@cursor.com>
@shnpd
shnpd requested review from Ljy-0827 and iuyo5678 and a lite review from Copilot September 2, 2026 11:27

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Port parsing and URL construction need to be made stricter/more robust (e.g., avoid parseInt-accepting malformed input and avoid manual URL concatenation that can break IPv6 formatting).

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR implements runtime configuration of the extension’s local daemon WebSocket port via the popup UI, persisting the setting in chrome.storage.local and updating the background connection behavior accordingly (addressing issue #114).

Changes:

  • Added a popup “Connection port” input with validation + persistence (bsk_daemon_port), plus friendlier disconnected-state messaging.
  • Updated background to read the stored port at startup and react to storage changes by updating the WebSocket URL and reconnecting.
  • Extended transport to allow runtime URL changes and added/updated docs + i18n + tests.
File summaries
File Description
packages/i18n/src/locales/zh-CN/extension.json Adds zh-CN strings for daemon port UI and unreachable messaging.
packages/i18n/src/locales/en-US/extension.json Adds en-US strings for daemon port UI and unreachable messaging.
docs/architecture.md Documents that the default daemon WS port is configurable via the popup.
apps/extension/src/transport/ws-transport.ts Allows updating transport URL via setUrl() without auto-reconnect.
apps/extension/src/transport/daemon-endpoint.ts New helpers for default port, URL resolution, and input/storage normalization.
apps/extension/src/transport/tests/ws-transport.test.ts Adds coverage for setUrl() behavior.
apps/extension/src/transport/tests/daemon-endpoint.test.ts Adds coverage for daemon endpoint URL/port parsing helpers.
apps/extension/src/lib/popup-bridge.ts Removes unused set_port message variant; port now stored via storage.
apps/extension/src/lib/instance-id.ts Adds get/set helpers and storage key for bsk_daemon_port.
apps/extension/src/lib/tests/instance-id.test.ts Adds tests for daemon port persistence/normalization.
apps/extension/src/entrypoints/popup/use-daemon-port.ts New hook to load/commit daemon port preference via chrome.storage.local.
apps/extension/src/entrypoints/popup/use-connection-state.ts Updates comment to reflect current popup bridge semantics.
apps/extension/src/entrypoints/popup/App.tsx Renders port input, adjusts disconnected messaging, and hides transport errors when disconnected.
apps/extension/src/entrypoints/popup/App.test.tsx Adds tests for disconnected UX and daemon port input behavior.
apps/extension/src/entrypoints/background.ts Reads stored port on startup and reconnects on storage updates.
apps/extension/PRIVACY.zh-CN.md Updates privacy text to note configurable loopback port.
apps/extension/PRIVACY.md Updates privacy text to note configurable loopback port.
Review details
  • Files reviewed: 17/17 changed files
  • Comments generated: 5
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread apps/extension/src/transport/daemon-endpoint.ts
Comment thread apps/extension/src/entrypoints/background.ts
Comment thread apps/extension/src/transport/daemon-endpoint.ts
Comment thread apps/extension/src/transport/daemon-endpoint.ts
Comment thread apps/extension/src/entrypoints/popup/use-daemon-port.ts
shnpd and others added 2 commits September 3, 2026 19:57
如果有字符就报错,不直接转为数字

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
修复注释不准确

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

Feature Request: Allow configuring daemon port in extension UI | 浏览器扩展支持配置 daemon 端口

2 participants