"""按 steps/*.json 的 actions 列表驱动 web_page 工具(真实浏览器/CDP 9222)。 用法: python drive.py steps/xxx.json [--save-png 前缀] """ import json import sys import time from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[3] / "Agent" / "src")) from agent.tools.web_page import WebPage as WebPageTool def main() -> None: path = Path(sys.argv[1] if len(sys.argv) > 1 else "steps/tmp.json") actions = json.loads(path.read_text(encoding="utf-8")) tool = WebPageTool() msg, artifact = tool._run(actions) print(msg) png = artifact.get("image_bytes") if png: out = Path(__file__).parent / "output" out.mkdir(exist_ok=True) name = path.stem + f"_{int(time.time())}.png" (out / name).write_bytes(png) print(f"[screenshot saved] {out / name}") if __name__ == "__main__": main()