Prefer Chromium for turnstilePatch on headless servers
Google Chrome blocks --load-extension, so CF tokens stay empty under Xvfb. Auto-select Chromium when the extension is present, install/ detect chromium in start.sh, and document browser_prefer overrides.
This commit is contained in:
1 parent
cd4a2351ae
commit
cf6c0d2b4d
7 files changed
+141
-45
No files matched your search
@@ -339,33 +339,58 @@ step3_sync_deps() {
|
||||
step4_check_browser() {
|
||||
echo -e "${CYAN}[4/6] 检测/安装浏览器...${NC}"
|
||||
|
||||
# Prefer Chromium for turnstilePatch (--load-extension works).
|
||||
# Google Chrome alone often leaves CF token=0 on Xvfb servers.
|
||||
local candidate
|
||||
local found_chromium=""
|
||||
local found_chrome=""
|
||||
for candidate in \
|
||||
google-chrome-stable google-chrome chromium chromium-browser \
|
||||
chromium chromium-browser \
|
||||
/usr/bin/chromium /usr/bin/chromium-browser /snap/bin/chromium; do
|
||||
if have_cmd "$candidate" || [ -x "$candidate" ] 2>/dev/null; then
|
||||
found_chromium="$(command -v "$candidate" 2>/dev/null || echo "$candidate")"
|
||||
break
|
||||
fi
|
||||
done
|
||||
for candidate in \
|
||||
google-chrome-stable google-chrome \
|
||||
/usr/bin/google-chrome-stable /usr/bin/google-chrome \
|
||||
/snap/bin/chromium /usr/bin/chromium /usr/bin/chromium-browser \
|
||||
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"; do
|
||||
if have_cmd "$candidate" || [ -x "$candidate" ] 2>/dev/null; then
|
||||
echo -e " ${GREEN}✓${NC} 浏览器: $(command -v "$candidate" 2>/dev/null || echo "$candidate")"
|
||||
return 0
|
||||
found_chrome="$(command -v "$candidate" 2>/dev/null || echo "$candidate")"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
echo -e " ${YELLOW}⚠${NC} 未检测到 Chrome/Chromium,尝试自动安装..."
|
||||
if [ -n "$found_chromium" ]; then
|
||||
echo -e " ${GREEN}✓${NC} Chromium: $found_chromium (可加载 turnstilePatch)"
|
||||
if [ -n "$found_chrome" ]; then
|
||||
echo -e " ${CYAN}·${NC} 另检测到 Chrome: $found_chrome(注册默认优先 Chromium)"
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ -n "$found_chrome" ]; then
|
||||
echo -e " ${YELLOW}⚠${NC} 仅有 Google Chrome: $found_chrome"
|
||||
echo " Chrome 无法加载 turnstilePatch,Turnstile 容易 token=0。"
|
||||
echo " 将尝试安装 Chromium..."
|
||||
else
|
||||
echo -e " ${YELLOW}⚠${NC} 未检测到 Chrome/Chromium,尝试自动安装 Chromium..."
|
||||
fi
|
||||
|
||||
local installed=false
|
||||
|
||||
# Debian/Ubuntu
|
||||
# Debian/Ubuntu — prefer chromium (extension support)
|
||||
if have_cmd apt-get; then
|
||||
if have_cmd sudo; then
|
||||
if sudo -n true 2>/dev/null; then
|
||||
echo " → 使用 apt 安装 chromium(免密 sudo)..."
|
||||
if sudo apt-get update -qq && sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -qq chromium-browser chromium 2>/dev/null; then
|
||||
if sudo apt-get update -qq && sudo DEBIAN_FRONTEND=noninteractive apt-get install -y -qq chromium chromium-browser 2>/dev/null; then
|
||||
installed=true
|
||||
fi
|
||||
else
|
||||
echo -e " ${YELLOW}⚠${NC} 检测到 apt,但需要交互 sudo,跳过自动安装浏览器"
|
||||
echo " 可手动: sudo apt install -y chromium-browser"
|
||||
echo " 可手动: sudo apt install -y chromium"
|
||||
fi
|
||||
fi
|
||||
# Arch
|
||||
@@ -388,23 +413,35 @@ step4_check_browser() {
|
||||
else
|
||||
echo " 可手动: sudo dnf install -y chromium"
|
||||
fi
|
||||
# macOS Homebrew
|
||||
# macOS Homebrew — chromium cask if available, else chrome
|
||||
elif have_cmd brew; then
|
||||
echo " → 使用 Homebrew 安装 Google Chrome..."
|
||||
if brew install --cask google-chrome 2>/dev/null; then
|
||||
echo " → 使用 Homebrew 安装 chromium / chrome..."
|
||||
if brew install --cask chromium 2>/dev/null || brew install --cask google-chrome 2>/dev/null; then
|
||||
installed=true
|
||||
fi
|
||||
fi
|
||||
|
||||
# 再检测一次
|
||||
# 再检测一次(Chromium 优先)
|
||||
for candidate in \
|
||||
google-chrome-stable google-chrome chromium chromium-browser \
|
||||
chromium chromium-browser \
|
||||
/usr/bin/chromium /usr/bin/chromium-browser /snap/bin/chromium \
|
||||
google-chrome-stable google-chrome \
|
||||
/usr/bin/google-chrome-stable /usr/bin/google-chrome \
|
||||
/snap/bin/chromium /usr/bin/chromium /usr/bin/chromium-browser \
|
||||
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"; do
|
||||
if have_cmd "$candidate" || [ -x "$candidate" ] 2>/dev/null; then
|
||||
echo -e " ${GREEN}✓${NC} 浏览器已就绪: $(command -v "$candidate" 2>/dev/null || echo "$candidate")"
|
||||
return 0
|
||||
local resolved
|
||||
resolved="$(command -v "$candidate" 2>/dev/null || echo "$candidate")"
|
||||
case "$resolved" in
|
||||
*chromium*)
|
||||
echo -e " ${GREEN}✓${NC} 浏览器已就绪 (Chromium): $resolved"
|
||||
return 0
|
||||
;;
|
||||
*)
|
||||
echo -e " ${YELLOW}⚠${NC} 仅有 Chrome: $resolved"
|
||||
echo " 注册机将用 CDP stealth;过 CF 仍建议: sudo apt install -y chromium"
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -412,12 +449,12 @@ step4_check_browser() {
|
||||
echo -e " ${YELLOW}⚠${NC} 安装命令已执行,但仍未在 PATH 中找到浏览器,请重启终端后重试"
|
||||
else
|
||||
echo -e " ${YELLOW}⚠${NC} 未能自动安装浏览器"
|
||||
echo " DrissionPage 需要 Chrome/Chromium;协议 mint 不强制浏览器,回退流程需要。"
|
||||
echo " 注册需要 Chromium(推荐,可加载 turnstilePatch)或 Chrome。"
|
||||
echo " 手动安装示例:"
|
||||
echo " Ubuntu/Debian: sudo apt install -y chromium-browser"
|
||||
echo " Ubuntu/Debian: sudo apt install -y chromium"
|
||||
echo " Arch: sudo pacman -S chromium"
|
||||
echo " macOS: brew install --cask google-chrome"
|
||||
echo " ${YELLOW}脚本将继续,注册可能因缺少浏览器而失败。${NC}"
|
||||
echo " macOS: brew install --cask chromium"
|
||||
echo " ${YELLOW}脚本将继续,注册可能因缺少浏览器 / Turnstile 失败。${NC}"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user