第8章 浏览器 Profile(账号配置)详解
每个客户使用独立登录 浏览器 Profile 保存一套网站账号和固定的出口位置。任务仅调用该 Profile 内的会话和已保存的密码。Profile 管理免费,任务执行则按套餐计费。 创建 Profile 创建 API 密钥
01 隔离 Profile 运行时无法看到其他登录状态,其登录信息也不会泄漏到 Default 中。
02 无需扩展 可在云任务中直接保存密码、登录或导入会话文件。
03 固定出口位置 每个 Profile 保留一个出口位置,若未手动设置,则自动锚定首次登录时的位置。
两类 Profile Profile 与 Default 每个账号都有 Default。你创建的命名 Profile 即为其余类型。在云端应用中,提示词下方的“登录”菜单可切换 Profile:创建、重命名、删除以及设置账号默认项均在此处操作。选择会保存在当前浏览器中。若选择了带有位置信息的 Profile,位置标签将随之切换。
REST API Profile 接口 基础 URL:https://mcp.rtrvr.ai/v1/profiles。使用与 /agent 和 /scrape 相同的 API 密钥(或 MCP OAuth 令牌)。响应仅列出名称:Cookie 值永不返回,且不提供导出功能。 RequestBody 返回 POST /v1/profiles { name, location?, proxyId?, makeDefault? } 201 { profile } GET /v1/profiles 无 { profiles, defaultProfileId } GET /v1/profiles/{id} 无 { profile, sites }(仅名称) PATCH /v1/profiles/{id} { name?, location?, proxyId?, makeDefault? } { profile } DELETE /v1/profiles/{id} 无 { deleted, sitesDeleted } PUT /v1/profiles/{id}/state 登录文件(见导入) { imported, sites, skipped, ignored } DELETE /v1/profiles/{id}/sites/{site} 无 { site, deleted, domains } 01 name 字符串 必填 1 至 60 字符,账号内唯一(不区分大小写)。“Default”为保留字。 02 location 对象 | 空 定义此 Profile 运行时的出口位置:{country, region?, city?},结构同 settings.proxyConfig.location。设为空则清除位置。 03 proxyId 字符串 | 空 云设置 → 代理配置中保存的代理 ID。Profile 运行时将使用该代理替代托管代理,从而保持 IP 一致。 04 makeDefault 布尔值 true 表示设为账号默认:API 和 MCP 中未指定 Profile 的运行将使用此项。对当前默认项设 false 则会回退至 Default。
创建 Profile curl -X POST https://mcp.rtrvr.ai/v1/profiles \ -H "Authorization: Bearer rtrvr_your_api_key" \ -H "Content-Type: application/json" \ -d '{"name": "Client A", "location": {"country": "US", "region": "NY", "city": "New York"}}'
使用 Profile 在 Profile 上运行 向 POST /agent、POST /scrape 或 MCP 的 cloud_agent 和 cloud_scrape 工具传递 profile(ID 或精确名称,或 "default")。 Profile 上的 Agent API curl -X POST https://api.rtrvr.ai/agent \ -H "Authorization: Bearer rtrvr_your_api_key" \ -H "Content-Type: application/json" \ -d '{ "input": "Download last month's invoices", "urls": ["https://billing.example.com/invoices"], "profile": "Client A" }' Profile 上的 MCP cloud_agent { "name": "cloud_agent", "arguments": { "user_input": "Reply to the newest support ticket", "urls": ["https://support.example.com"], "profile": "Client A" } } 01 profile 字符串 省略则使用账号默认 Profile(未设置时为 Default)。延续此前运行的任务将保持在该 Profile 上。 02 session_source 仅限 MCP 仍适用于单设备登录或 "none"。二者选一,不可同时传递。 03 settings.proxyConfig 对象 请求中指定的路由优先于 Profile 的位置或已保存的代理。 MCP 结果中的 logins 字段标明任务使用的 Profile。定时任务遵循其保存请求中指定的 Profile,而非后续变更的账号默认项。
携带你的登录信息 导入登录文件 将文件发送至 PUT /v1/profiles/{id}/state,或在云端应用的“登录”菜单导入框中拖放。文件中的每个网站将替换该 Profile 中对应网站的会话;其他网站和密码保持不变。添加 "replace": true 可先清除其他所有网站。 导入 # Playwright storageState 文件 curl -X PUT https://mcp.rtrvr.ai/v1/profiles/PROFILE_ID/state \ -H "Authorization: Bearer rtrvr_your_api_key" \ -H "Content-Type: application/json" \ --data-binary @state.json
# cookies.txt 文件 curl -X PUT https://mcp.rtrvr.ai/v1/profiles/PROFILE_ID/state \ -H "Authorization: Bearer rtrvr_your_api_key" \ -H "Content-Type: text/plain" \ --data-binary @cookies.txt
# Cookie 头:需指定发送页面 curl -X PUT https://mcp.rtrvr.ai/v1/profiles/PROFILE_ID/state \ -H "Authorization: Bearer rtrvr_your_api_key" \ -H "Content-Type: application/json" \ -d '{"content": "Cookie: session=...; csrftoken=...", "url": "https://app.example.com/"}'
格式 获取方式 Playwright storageState JSON 登录后执行 await context.storageState({ path: "state.json" })(代码片段见下文)。localStorage 不会被导入;响应会显示排除的源数量。 Cookie-Editor 或 EditThisCookie JSON 在已登录网站上打开扩展并导出为 JSON。 Netscape cookies.txt “Get cookies.txt” 样式导出器、curl -c 或 yt-dlp --cookies。#HttpOnly_ 行保留为 HttpOnly。 DevTools “复制为 cURL” Chrome DevTools → 网络 → 重新加载已登录页面 → 右键首个请求 → 复制 → 复制为 cURL (bash 或 cmd)。粘贴至“从 DevTools 粘贴”。 Cookie 头 + URL DevTools 中请求的 Cookie 头及发送该请求的页面 URL。 保存 Playwright storageState // Playwright 登录后: await context.storageState({ path: "state.json" })
// 或手动登录一次后保存状态: const browser = await chromium.launch({ headless: false }) const context = await browser.newContext() const page = await context.newPage() await page.goto("https://app.example.com/login") // …在弹出的窗口中登录… await context.storageState({ path: "state.json" }) 限制:每文件 2 MB,100 个网站,每网站 300 个 Cookie,每账号每小时 30 次导入。过期 Cookie 会被跳过。每个网站均根据 Cookie 名称进行登录检查,以便立即知晓哪些网站携带登录状态。
保持访客身份一致 位置锚定 网站会察觉到频繁跨国切换的登录。Profile 保持任务出口位置固定。 相互隔离 Profile 登录的存储方式 Cookie 值和网站登录状态使用 Profile 专属密钥加密(AES-256-GCM),该密钥由 Google Cloud KMS 保护。保存的密码和设置密钥单独密封,永不显示。 名称、网站和登录检查保持可读,因此列表和登录芯片无需解密即可工作。 仅该 Profile 上的云端运行会解密这些内容。列表和 API 仅返回名称,且不提供导出。 你的下一次运行 在真实网站上运行示例 使用 Chrome 处理当前页面。若需按计划继续运行或跨多个页面操作,请使用 Cloud。