FluxBrowserDocs
FluxBrowser
FluxBrowser
  1. 自动化
  • 快速开始
  • 开发者文档
  • 自动化
    • Playwright
    • Puppeteer
    • Selenium
  • Browser
    • 获取环境列表(全量)
      POST
    • 启动浏览器(支持批量)
      POST
    • 停止浏览器(支持批量)
      POST
  • 数据模型
    • BasicsResultBase
    • OpenEnvironmentsRequest
    • OpenEnvironmentItem
    • OpenLaunchRequest
    • OpenStopRequest
    • OpenLaunchResultItem
    • OpenStopResultItem
    • OpenLaunchData
    • OpenStopData
    • OpenEnvironmentsData
    • BasicsResultOpenLaunch
    • BasicsResultOpenStop
    • BasicsResultOpenEnvironments
  1. 自动化

Playwright

在成功调用开放 API 启动(见 快速开始)后,从响应中取 data.results[i].webSocketDebuggerUrl(且 success === true),通过 CDP 连接已运行的 Chromium 内核。

依赖#

示例(Node.js / TypeScript)#

import { chromium } from "playwright";

const base = process.env.FLUX_API_BASE ?? "http://localhost:8026/api/v1";
const apiKey = process.env.FLUX_API_KEY!;
const envId = process.env.FLUX_ENV_ID!;

async function launchAndConnect() {
  const launchRes = await fetch(`${base}/open/browser/launch`, {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ apiKey, envIds: [envId] }),
  });
  const launchJson = await launchRes.json();
  if (!launchJson.succeed) throw new Error(launchJson.msg ?? "launch failed");

  const item = launchJson.data?.results?.[0];
  if (!item?.success || !item.webSocketDebuggerUrl) {
    throw new Error(item?.error ?? "no webSocketDebuggerUrl");
  }

  const browser = await chromium.connectOverCDP(item.webSocketDebuggerUrl);
  const context = browser.contexts()[0] ?? (await browser.newContext());
  const page = context.pages()[0] ?? (await context.newPage());
  await page.goto("https://example.com");
  // …你的自动化逻辑

  await browser.close();
}

launchAndConnect().catch(console.error);

说明#

connectOverCDP 使用 DevTools WebSocket 地址,与 Puppeteer 的 browserWSEndpoint 同类。
若仅 port 有值而 WS 为空,请以实际 JSON 为准或检查本机指纹浏览器服务版本。
停止环境请调用 POST /open/browser/stop(相同 apiKey + envIds)。
修改于 2026-04-12 12:57:48
上一页
开发者文档
下一页
Puppeteer
Built with