Files
2025-11-30 09:05:55 +08:00

2.3 KiB
Raw Permalink Blame History

Command Reference

All scripts accept the shared flags --json, --quiet, --port=<number>, --host=<host>, --ws=<endpoint>, and --timeout=<ms>. Without --json, STDOUT still emits machine-readable JSON while human logs go to STDERR.

start.js

node scripts/start.js [--profile[=path]] [--chrome-path=<path>] [--user-data-dir=<path>]
  • Detects Chrome/Chromium automatically across macOS, Linux, and Windows.
  • Copies the default browser profile when --profile is set, or from a custom path when supplied.
  • Returns { ok, port, userDataDir, chromePath, profile }.

navigate.js

node scripts/navigate.js <url> [--new] [--wait=domcontentloaded|networkidle0|load|none]
  • Reuses the active tab by default; --new opens a new page.
  • Emits { ok, url, newPage }.

evaluate.js

node scripts/evaluate.js <expression>
node scripts/evaluate.js --file snippet.js
  • Supports inline, file-based, or piped expressions; structured clone results are returned under result.
  • When not in --json mode the evaluated value (truncated to 8KB) is echoed to STDOUT.

screenshot.js

node scripts/screenshot.js [--element=<selector>] [--format=png|jpeg] [--quality=80] [--out=path]
  • Saves to a temporary directory when --out is omitted and prints the absolute path.
  • Element captures rely on the supplied selector; full-page captures default to PNG.

element.js

node scripts/element.js <selector>
node scripts/element.js --text "Buy now"
node scripts/element.js             # interactive picker
  • --click and --scroll act on the resolved element before returning metadata.
  • Interactive mode waits up to 60s for a click inside Chrome and restores page styling afterwards.

cookies.js

node scripts/cookies.js --export [path] [--domain=example.com]
node scripts/cookies.js --import cookies.json
node scripts/cookies.js --clear [--domain=example.com]
  • Uses Chrome DevTools Network.* commands for reliable cookie management.
  • Export payloads include metadata (exportedAt, pageUrl, cookies[]).

close.js

node scripts/close.js [--force]
  • Attempts graceful shutdown first; falls back to process termination on failure.
  • Returns { ok, port, graceful, forced, closedTabs }.