linege-sdk
v0.1.3
Published
Node/Bun SDK for Linege automation: - Cloud API client - Local sidecar (WSS) server/client - Chrome launcher with Linege flags
Readme
linege-sdk (internal)
Node/Bun SDK for Linege automation:
- Cloud API client
- Local sidecar (WSS) server/client
- Chrome launcher with Linege flags
Quick usage
import { LinegeApi, SidecarServer, SidecarClient, launchChrome } from "linege-sdk";
const api = new LinegeApi({ apiUrl: "http://localhost:3000", token: process.env.API_TOKEN });
const env = await api.createEnvironment({ country: "US", name: "sdk-test" });
const sidecar = new SidecarServer({ port: 0 });
const controlPort = await sidecar.start();
const launched = await launchChrome({
// Option A: explicit path
chromePath: "D:\chromium\src-bb\out\Static\chrome.exe",
// Option B: auto-pick by branch (uses CHROMIUM_ROOT or D:\chromium)
// chromeBranch: "src-bb",
envId: env.env_id,
profile: env.profile,
proxy: env.proxy,
controlPort,
});
const client = new SidecarClient({ url: `ws://127.0.0.1:${controlPort}/chrome` });
await client.connect();
client.register(env.env_id);
client.claimMaster({ x: 0, y: 0, width: 1000, height: 800 });
client.sendInput({ type: "mousedown", x: 100, y: 100, button: 0 });产品友好 API(推荐)
import { LinegeSession } from "linege-sdk";
const session = await LinegeSession.create({
apiBase: process.env.API_BASE_CLOUD!,
apiToken: process.env.API_TOKEN_CLOUD!,
country: "JP",
startUrl: "https://example.com"
});
await session.waitForTextContains("Example Domain");
await session.openTab("https://httpbin.org/forms/post");
await session.waitForNewTab();
await session.fill('input[name="custname"]', "linege-user");
session.close();Examples
# Product-friendly tutorial (recommended)
API_BASE=https://api.example.com/api/v1 API_TOKEN=sk_live_xxx CHROME_PATH=D:\chromium\src\out\Static\chrome.exe \
npm run example:tutorial
# Full flow: cloud API -> env -> local profile -> launch chrome -> sidecar input
API_BASE=https://api.example.com/api/v1 API_TOKEN=sk_live_xxx COUNTRY=JP CHROME_PATH=D:\chromium\src\out\Static\chrome.exe \
npm run example:basic
# Use branch auto-pick (Windows default root: D:\chromium)
LINEGE_CHROME_BRANCH=src-bb npm run example:basic
# Full automation (CDP + browserscan). Falls back to no-proxy if SOCKS fails.
API_BASE=https://api.example.com/api/v1 API_TOKEN=sk_live_xxx COUNTRY=JP CHROME_PATH=D:\chromium\src\out\Static\chrome.exe HOLD_MS=15000 \
npm run example:full
# Connect to existing sidecar port (no chrome launch)
SIDECAR_PORT=65141 npm run example:sidecarDocs
DOCS.md
