内网离线安装playwright
2026-5-27
根据: https://github.com/ji233-Sun/playwright-install-linux-china
对于playwright v1.57+
-
下载 chrome for testing 的对应版本,自行替换下面的url内的版本号
https://cdn.npmmirror.com/binaries/chrome-for-testing/148.0.7778.96/win64/chrome-win64.zip
chromium-headless-shell-win64.zip
ffmpeg-win64.zip
winldd-win64.zip -
将chromium重命名为chrome, 设置环境变量
$env:PLAYWRIGHT_DOWNLOAD_HOST="http://localhost:8000"
$env:PLAYWRIGHT_CHROMIUM_DOWNLOAD_HOST="http://localhost:8000"
python -m http.server
# playwright install browser
2026-5-6
TODO: 想做一个内网自动安装的脚本了……油猴+python
js脚本访问
- 获取npmmirror镜像站最新的builds版本号 https://registry.npmmirror.com/-/binary/playwright/builds/chromium/ ,找date最大的值, 这里是
1200. 并下载对应的2个二进制zip- 获取最新release版本号: v1.57
- 读取github的browser.json,替换下方url的替换release-1.xx分支。版本默认降低5个,二分法确定对应的
revision: 1200
https://raw.githubusercontent.com/microsoft/playwright/refs/heads/release-1.57/packages/playwright-core/browsers.json- 弹窗以shell命令返回:bun i playwright@v1.57 @playwright/mcp@0.0.x ,提示用户按指定的结构放置。mkdir -p builds/chromium/1200/
- python脚本负责启动http服务器,根据桌面的.lnk修改index.js, 然后执行shell: playwright install; playwright-mcp install-browser. 默认lnk ~.bun/install/global/node_modules/playwright/node_modules/playwright-core/lib/server/registry/index.js 或 mcp lib/coreBundle.js
- 验证 playwright install; playwright-mcp install-browser chromium 退出码
- playwright v1.57
- playwright-mcp v0.0.47
npmmirror国内镜像 v1200: chromium-win64.zip chromium-headless-shell-win64.zip
2026-4-15 playwright v1.59.1
playwright install chromium firefox
步骤
- 根据报错,下载版本匹配的 chromium-win64.zip chromium-headless-shell-win64.zip winldd-win64.zip (这个链接是2025-8月的1187版本for windows x86_64)
pip install mitmproxy- 复制下面脚本为
redirect.py,修改REMAP变量为代理地址:本地路径:
redirect.py
#!/bin/env mitmdump -s redirect.py -p 8080 --mode upstream:http://localhost:10808
"""
TODO: currently you need to install manually mitmproxy .pem certificate into system trust store
"""""
from mitmproxy import http, ctx
from mitmproxy.http import Response
Log = ctx.log
REMAP = {
"http://127.0.0.1:8080/builds/chromium/1187/chromium-win64.zip": r"~/Downloads/chromium-win64.zip",
"http://127.0.0.1:8080/builds/chromium/1187/chromium-headless-shell-win64.zip": r"~/Downloads/chromium-headless-shell-win64.zip",
"http://127.0.0.1:8080/builds/chromium/1007/winldd-win64.zip": r"~/Downloads/winldd-win64.zip"
}
def request(flow: http.HTTPFlow) -> None:
file = REMAP.get(flow.request.url, None)
if file:
Log.info(f"[Remap ? →裟]\t{flow.request.url=}")
try:
# 读取本地文件内容
with open(file, "rb") as f:
content = f.read()
if len(content) == 0:
Log.warn(f"Local {file=} is empty.")
# 可选操作:返回空响应
flow.response = Response.make(
204, b"", {"Content-Type": "text/plain"} # 无内容
)
return
# 构建响应
flow.response = Response.make(
200, # 状态码
content, # 响应内容
{"Content-Type": "application/octet-stream"}, # 响应头
)
Log.info(f"' {file=}")
except Exception as e:
Log.warn(e)
# 可选操作:返回错误响应
flow.response = Response.make(
500, # 内部服务器错误
b"Failed to load local file",
{"Content-Type": "text/plain"},
)
else:
Log.info(f"[Direct]\t{flow.request.url=}")
mitmweb -s redirct.py -p 10086(可将mitmweb替换为mitmdump)- 修改playwright的安装脚本,将
https://cdn.playwright.dev/dbazure/download/playwright替换为http://127.0.0.1:8080。版本号在node_modules/playwright-core/browsers.json查询。- 若是npm安装的js版本playwright,则其位置在
项目目录/node_modules/playwright-core/lib/server/registry/index.js - 若是pip安装的pypi包,自己找一下,全局搜索就能出来(😜知道的小伙伴在评论区告诉我一下)
- 若是npm安装的js版本playwright,则其位置在
bun x playwright install(bun可替换为pnpm)重新触发playwright的安装脚本,OK!
起因
slidv 导出需要 playwright

浙公网安备 33010602011771号