bb-browser 0.1.2 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,20 @@
1
- const DAEMON_PORT = 19824;
2
- const DAEMON_HOST = "localhost";
3
- const DAEMON_BASE_URL = `http://${DAEMON_HOST}:${DAEMON_PORT}`;
1
+ const DEFAULT_DAEMON_PORT = 19824;
2
+ const DEFAULT_DAEMON_HOST = "localhost";
3
+ const DEFAULT_DAEMON_BASE_URL = `http://${DEFAULT_DAEMON_HOST}:${DEFAULT_DAEMON_PORT}`;
4
4
  const SSE_RECONNECT_DELAY = 3e3;
5
5
  const SSE_MAX_RECONNECT_ATTEMPTS = 5;
6
+ const STORAGE_KEY = "upstreamUrl";
7
+ async function getUpstreamUrl() {
8
+ try {
9
+ const result = await chrome.storage.sync.get(STORAGE_KEY);
10
+ const url = result[STORAGE_KEY];
11
+ if (url && typeof url === "string" && url.trim()) {
12
+ return url.trim().replace(/\/+$/, "");
13
+ }
14
+ } catch {
15
+ }
16
+ return DEFAULT_DAEMON_BASE_URL;
17
+ }
6
18
 
7
19
  class SSEClient {
8
20
  constructor() {
@@ -19,7 +31,8 @@ class SSEClient {
19
31
  console.warn("[SSEClient] Already connected");
20
32
  return;
21
33
  }
22
- const sseUrl = `${DAEMON_BASE_URL}/sse`;
34
+ const baseUrl = await getUpstreamUrl();
35
+ const sseUrl = `${baseUrl}/sse`;
23
36
  console.log("[SSEClient] Connecting to:", sseUrl);
24
37
  this.abortController = new AbortController();
25
38
  try {
@@ -174,7 +187,8 @@ class SSEClient {
174
187
  }
175
188
 
176
189
  async function sendResult(result) {
177
- const url = `${DAEMON_BASE_URL}/result`;
190
+ const baseUrl = await getUpstreamUrl();
191
+ const url = `${baseUrl}/result`;
178
192
  console.log("[APIClient] Sending result:", result.id, result.success);
179
193
  try {
180
194
  const response = await fetch(url, {
@@ -2969,6 +2983,14 @@ async function handleTrace(command) {
2969
2983
  const KEEPALIVE_ALARM = "bb-browser-keepalive";
2970
2984
  const sseClient = new SSEClient();
2971
2985
  sseClient.onCommand(handleCommand);
2986
+ chrome.storage.onChanged.addListener((changes, area) => {
2987
+ if (area === "sync" && changes.upstreamUrl) {
2988
+ const newUrl = changes.upstreamUrl.newValue || "default";
2989
+ console.log("[bb-browser] Upstream URL changed to:", newUrl, "— reconnecting...");
2990
+ sseClient.disconnect();
2991
+ sseClient.connect();
2992
+ }
2993
+ });
2972
2994
  chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
2973
2995
  console.log("[bb-browser] Message from content script:", message, "sender:", sender.tab?.id);
2974
2996
  sendResponse({ received: true });