Profile 与持久化
在多次运行之间保持同一个身份:复用指纹种子,把 Cookie 和存储保存在 Profile 目录中,或上报从真实 Chrome 采集的值。
导入真实 Chrome 的指纹 profile
除了由种子(seed)派生的合成身份画像,你还可以让 Clearcote 上报从真实机器采集的值。可以用 tools/fingerprint-collect 中的采集器从一台作为样本来源的 Chrome 上采集(打开 collect.html,点击 Capture,它会下载一个 JSON profile),也可以用自带的 convert_dataset.py 转换器,基于开源的 chrome-fingerprints 数据集(10k 条记录)快速起步。采集内容包括 navigator、屏幕几何参数、WebGL vendor/renderer + getParameter 限制值、Web Audio、语音合成音色、字体、编解码器,以及 CSS @media 特性。
把 profile 以文件路径、对象或 JSON 字符串的形式传给 SDK 即可——gzip + base64 打包由它代劳。profile 中存在的字段会覆盖浏览器原本上报的值;缺失的字段则回退到浏览器的默认值。如果你没有显式设置 Accept-Language,SDK 还会根据 profile 的 navigator.languages 推导出它。两种构建都能读取导入的 profile;在授权版构建上,从 151 r19 起完全生效。
不要在使用 profile 的同时传入 fingerprint 种子。种子会启用 farbling 层,严格的评分会把它判读为 canvas 篡改,而且它提供的东西 profile 本来就已经提供了。二者选其一。profile 只替换上报的值——它不会改变实际负责渲染像素的部分,所以同一台机器上的两个账号即使用了两个不同的 profile,产生的 canvas 仍然完全相同。如果需要按账号区分渲染结果,请为每个账号使用单独的种子,并且不使用 profile。
from clearcote import launch
browser = launch(fingerprint_profile="profile.json", disable_gpu_fingerprint=True, fingerprint_noise=False)
page = browser.new_page()
page.goto("https://example.com")
browser.close()Profile & 持久化
重复使用同一个 fingerprint 种子,就能在多次运行之间保持稳定的身份;再配合 user-data 目录,即可持久化 Cookie 和存储:
from clearcote import launch_persistent_context
ctx = launch_persistent_context(r"C:\clearcote\profiles\acme", fingerprint="acme-tenant-7", headless=False)
page = ctx.pages[0] if ctx.pages else ctx.new_page()profile 目录中的 Cookie 使用与创建该目录的机器绑定的密钥加密。如需把 profile 连同 Cookie 一起复制到另一台机器,请传入 portableProfile: true / portable_profile=True(密钥随 profile 一起迁移)或 encryptionKey / encryption_key(密钥由你提供的 secret 派生,不会有任何敏感信息写入磁盘)。仅限授权版构建,支持 Python & Node。
SDK 还支持保存身份画像:Profile 会把指纹选项、代理设置、canvas bridge 设置及其他启动选项以 JSON 形式存放在 ~/.clearcote/profiles 下(可用 CLEARCOTE_PROFILE_DIR 覆盖)。
from clearcote import Profile, launch, launch_persistent_context
Profile("acct-1", {
"fingerprint": "acct-1",
"gpu_vendor": "Google Inc. (Intel)",
"gpu_renderer": "ANGLE (Intel, Intel(R) UHD Graphics ... D3D11)",
"canvas_bridge": {"url": "ws://127.0.0.1:8443", "auth": "user:secret"},
}).save()
ctx = launch_persistent_context(r"C:\clearcote\profiles\acct-1", profile="acct-1")
browser = launch(profile="acct-1", headless=False)已保存的 profile 是明文存储的,可能包含 canvasBridge.auth 之类的凭据。请把 profile 文件当作受信任的输入对待,不要提交到代码仓库,也不要分享给他人。