xpzouying/xiaohongshu-mcp · critical

当前平台 %s/%s 无预编译浏览器,暂不支持

Error message

当前平台 %s/%s 无预编译浏览器,暂不支持

What it means

EnsureBrowser 的平台支持守卫:platformAsset() 对当前 runtime.GOOS/runtime.GOARCH 组合没有对应的预编译浏览器资产,即该操作系统/架构不在内置浏览器分发列表中,属环境不支持而非下载故障。

Source

Thrown at browser/browser_download.go:74

		return "windows-x64.zip", "chrome.exe", true
	}
	return "", "", false
}

func browserCacheDir() (string, error) {
	base, err := os.UserCacheDir()
	if err != nil {
		return "", err
	}
	return filepath.Join(base, "xiaohongshu-mcp", "browser", browserVersion), nil
}

// EnsureBrowser 确保本地存在内置浏览器二进制,返回其路径。
// 已缓存则直接返回;否则下载 → 校验 SHA256 → 解压。当前平台无预编译二进制时返回 error。
func EnsureBrowser() (string, error) {
	asset, binName, ok := platformAsset()
	if !ok {
		return "", fmt.Errorf("当前平台 %s/%s 无预编译浏览器,暂不支持", runtime.GOOS, runtime.GOARCH)
	}

	cacheDir, err := browserCacheDir()
	if err != nil {
		return "", err
	}

	// 已缓存:遍历查找二进制
	if bin := findBinary(cacheDir, binName); bin != "" {
		return bin, nil
	}

	if err := os.MkdirAll(cacheDir, 0o755); err != nil {
		return "", err
	}

	// 下载(重试 3 次)
	logrus.Infof("首次运行:下载内置浏览器 %s(%s,约 140-190MB,仅一次)...", browserVersion, asset)

View on GitHub (pinned to 332d196854)

Solutions

  1. 在支持的平台上运行:darwin/arm64、linux/amd64 或 windows/amd64
  2. 自建对应平台的 Chromium 并通过系统浏览器路径启动(绕过内置浏览器下载)
  3. 若必须支持该平台,向 platformAsset 增加对应 asset 并提供下载/SHA256
  4. 在文档/启动检查中提前提示平台要求

Example fix

// before
bin, err := browser.EnsureBrowser() // linux/arm64 上报错
// after
if !isSupportedPlatform() {
	return fmt.Errorf("unsupported platform %s/%s", runtime.GOOS, runtime.GOARCH)
}
bin, err := browser.EnsureBrowser()
Defensive patterns

Strategy: fallback

Validate before calling

func platformSupported() bool {
	switch runtime.GOOS {
	case "darwin":
		return runtime.GOARCH == "arm64"
	case "linux", "windows":
		return runtime.GOARCH == "amd64"
	}
	return false
}
// 部署/启动前: if !platformSupported() { ... }

Type guard

func isSupportedPlatform() bool {
	return (runtime.GOOS == "linux" && runtime.GOARCH == "amd64") ||
		(runtime.GOOS == "windows" && runtime.GOARCH == "amd64") ||
		(runtime.GOOS == "darwin" && runtime.GOARCH == "arm64")
}

Prevention

When it happens

Trigger: 在不支持的平台调用 EnsureBrowser(直接或经 NewBrowser):linux/arm64(如 ARM 云主机、树莓派)、darwin/amd64(Intel Mac)、freebsd 等。

Common situations: 在 ARM Linux 服务器/容器中部署;仍在 Intel Mac 上运行;CI 使用非 amd64 runner。

Understand the failure class

Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.


AI-assisted analysis of xpzouying/xiaohongshu-mcp@332d196854 (2026-09-05). Data as JSON: /api/errors/78b46510fc453415. Report an issue: GitHub.