From 401b549fb3aa56e3e8c5dfb7805a89e7e9b3158a Mon Sep 17 00:00:00 2001 From: ming_jiang Date: Thu, 12 Nov 2026 09:33:24 +0800 Subject: [PATCH] amp-usage 0.1.1: the Windows window is this computer, not a remote browser (#1025) On Windows magpie's window is http://wails.localhost (WebView2). page/boot.js counted only localhost, 127.0.0.1 and an empty host as this computer, so the Windows window got the "remote browser" message (#1024). It now counts *.localhost, ::1 and 127.* too, the same rule as chat, fingerprint, kimi-desktop, page-model-quota and window-warmup. magpie.service still wins. What was run at 84a6a812739b96191e9d63805cd408e0abef717a (mote, macOS): - boot.js in a node vm with a mocked location and magpie bridge, new and old side by side. wails.localhost, WAILS.LOCALHOST, 127.0.0.2 and [::1]: old shows the remote message, new opens http://127.0.0.1:3497/. localhost, 127.0.0.1 and an empty host open it in both. 192.168.1.5, evil.com and localhost.evil.com show the remote message in both. A magpie.service is used in both. - packages/amp-usage: node --test test/*.test.mjs, 48 pass, 0 fail. bun scripts/check.mjs amp-usage passed. Not tried: a real magpie window on Windows. No test of boot.js in the package yet. Co-authored-by: overstarry --- packages/amp-usage/package.json | 2 +- packages/amp-usage/page/boot.js | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/amp-usage/package.json b/packages/amp-usage/package.json index f9d4061..eec723b 100644 --- a/packages/amp-usage/package.json +++ b/packages/amp-usage/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/page-amp-usage", - "version": "0.1.0", + "version": "0.1.1", "description": "An Amp usage board in Magpie's window, with a local background service that can sync Amp usage into Magpie's usage ledger.", "type": "module", "main": "./index.mjs", diff --git a/packages/amp-usage/page/boot.js b/packages/amp-usage/page/boot.js index 51cd4f2..4533f51 100644 --- a/packages/amp-usage/page/boot.js +++ b/packages/amp-usage/page/boot.js @@ -41,11 +41,17 @@ const port = Number(options?.port ?? 3497); if (!Number.isInteger(port) || port < 1 || port > 65535) throw new Error("port"); + // This computer's window: wails://localhost on macOS and Linux, + // http://wails.localhost on Windows (Wails v3, WebView2). + const host = location.hostname.toLowerCase().replace(/^\[|\]$/g, ""); + const local = + host === "" || + host === "localhost" || + host.endsWith(".localhost") || + host === "::1" || + /^127\./.test(host); const target = - magpie.service || - (["localhost", "127.0.0.1", ""].includes(location.hostname) - ? `http://127.0.0.1:${port}/` - : ""); + magpie.service || (local ? `http://127.0.0.1:${port}/` : ""); if (!target) throw new Error("remote"); const url = new URL(target); url.searchParams.set("theme", theme.dark ? "dark" : "light");