Alphakdeps.io is experimental and evolving — the registry and packages may change or reset.
Toolkdeps asset

kdeps-tools-browser

v1.0.0

Drive a real browser with Playwright: open a page, run ordered steps (navigate, click, fill, type, upload, select, check, uncheck, hover, scroll, press, clear, evaluate, screenshot, wait), then return the page URL, title, text and each step's result. Use for pages that need JavaScript, a login or a form. Use web_scraper for a plain page.

set tools / shelf tools

LLM context: ~589 tokens when loaded (prompt or tool definition)

Where it runs

Part of the tools set, used in workflow and agent mode. What the model is told about each built-in tool: its description, usage notes and parameters. kdeps runs the tool itself.

  1. the agent loop builds the request
  2. the tool definitions are sent to the modeltools/browser
  3. the model calls a tool
  4. kdeps runs it
  5. the result goes back to the model

Loaded by: kdeps (agent loop), kdeps new, kdeps run, kdeps install, kdeps list, kdeps uninstall, kdeps update, kdeps upgrade

In the code: kdeps (agent loop)executor.(*Engine).Executeparallel.Runjudge.Panelagent.runJudgePanelagent.definedAs

Install

A kdeps asset: installed with the first-run profile that includes its set, or the first time a command needs it, and updated without a new release.

kdeps install tools/browser

Pin a version with kdeps install tools/browser@<version>.

Contents

Drive a real browser with Playwright: open a page, run ordered steps (navigate, click, fill, type, upload, select, check, uncheck, hover, scroll, press, clear, evaluate, screenshot, wait), then return the page URL, title, text and each step's result. Use for pages that need JavaScript, a login or a form. Use web_scraper for a plain page.

category
web
seeAlso
web_scraper, http_request
ParameterTypeDescription
urlstringPage to open first. With a sessionId and no url, the session's last page.
actionsarraySteps in order, e.g. [{action: fill, selector: "#q", value: kdeps}, {action: press, key: Enter}]. Step fields: action (required), selector, value, key, script, files, outputFile, fullPage, wait, url.
enginestringchromium (default), firefox or webkit. The engine's browser downloads on first use.
headlessbooleanRun without a window. Default: true.
sessionIdstringKeep cookies, storage and the current page between calls with the same id (under ~/.kdeps/browser-sessions).
viewportobject{width, height}. Default: 1280x720.
timeoutstringPer-step timeout as a duration. Default: 30s.
waitForstringSelector to wait for after the first page loads.
userAgentstringUser-Agent override.
stealthModebooleanLaunch flags and context settings that make automation less detectable. Default: false.
extractstringSelector of the element whose text the result holds. Default: body.
maxTextintegerMost characters of text in the result. Default: 20000.
sincestringA hash from an earlier call. When the text still has that hash, changed is empty. A poll listener passes its cursor here to watch a page.

Python script (declared in YAML, no Go code)

# Runs the browser steps with Playwright and prints the result as JSON.
import hashlib, json, os, re, subprocess, sys, tempfile, time
from playwright.sync_api import sync_playwright, Error as PlaywrightError

args = json.loads(sys.argv[1])

def arg(name, default=""):
    v = args.get(name)
    return default if v in (None, "") else v

def flag(name, default):
    v = args.get(name)
    if isinstance(v, bool):
        return v
    if v in (None, ""):
        return default
    return str(v).lower() == "true"

def as_json(v, default):
    if isinstance(v, str):
        return json.loads(v) if v.strip() else default
    return default if v is None else v

url = str(arg("url"))
actions = as_json(args.get("actions"), []) or []
viewport = as_json(args.get("viewport"), {}) or {}
engine = str(arg("engine", "chromium")).lower()
headless = flag("headless", True)
stealth = flag("stealthMode", False)
session_id = str(arg("sessionId"))
wait_for = str(arg("waitFor"))
extract = str(arg("extract", "body"))
max_text = int(arg("maxText", 20000))
since = str(arg("since"))

def seconds(d, default=30.0):
    m = re.fullmatch(r"\s*(\d+(?:\.\d+)?)(ms|s|m|h)?\s*", str(d or ""))
    if not m:
        return default
    return float(m.group(1)) * {"ms": 0.001, "s": 1, "m": 60, "h": 3600, None: 1}[m.group(2)]

tms = seconds(arg("timeout", "30s")) * 1000
state_dir = os.path.join(os.path.expanduser("~"), ".kdeps", "browser-sessions")
safe_id = re.sub(r"[^A-Za-z0-9._-]", "_", session_id)
state_file = os.path.join(state_dir, safe_id + ".json") if session_id else ""
url_file = os.path.join(state_dir, safe_id + ".url") if session_id else ""
stealth_args = ["--disable-blink-features=AutomationControlled", "--no-sandbox",
                "--disable-setuid-sandbox", "--disable-dev-shm-usage", "--no-first-run",
                "--disable-gpu", "--window-size=1280,720"]

def launch(pw):
    kind = {"firefox": pw.firefox, "webkit": pw.webkit}.get(engine, pw.chromium)
    opts = {"headless": headless, "args": stealth_args if stealth else []}
    try:
        return kind.launch(**opts)
    except PlaywrightError as e:
        if "Executable doesn't exist" not in str(e):
            raise
        # First use: download this engine's browser, then retry.
        sys.stderr.write("browser: installing %s (first use only)...\n" % engine)
        subprocess.run([sys.executable, "-m", "playwright", "install", engine], check=True,
                       stdout=sys.stderr)
        return kind.launch(**opts)

def value(a, *keys):
    for k in keys:
        if a.get(k) not in (None, ""):
            return str(a[k])
    return ""

def run(page, a):
    kind = str(a.get("action", "")).lower()
    sel = value(a, "selector")
    base = {"action": a.get("action", "")}
    if sel:
        base["selector"] = sel

    def need_sel():
        if not sel:
            raise ValueError("%s: missing selector" % kind)

    if kind == "navigate":
        dest = value(a, "url", "value")
        if not dest:
            raise ValueError("navigate: missing url")
        page.goto(dest, timeout=tms)
        base["url"] = dest
    elif kind in ("click", "check", "uncheck", "hover", "clear"):
        need_sel()
        getattr(page.locator(sel), kind)(timeout=tms)
    elif kind == "fill":
        need_sel()
        page.locator(sel).fill(value(a, "value"), timeout=tms)
        base["value"] = value(a, "value")
    elif kind == "type":
        need_sel()
        page.locator(sel).press_sequentially(value(a, "value"), timeout=tms)
        base["value"] = value(a, "value")
    elif kind == "upload":
        need_sel()
        files = a.get("files") or []
        if not files:
            raise ValueError("upload: no files specified")
        page.locator(sel).set_input_files(files, timeout=tms)
        base["files"] = files
    elif kind == "select":
        need_sel()
        page.locator(sel).select_option(value(a, "value"), timeout=tms)
        base["value"] = value(a, "value")
    elif kind == "scroll":
        if sel:
            page.locator(sel).scroll_into_view_if_needed(timeout=tms)
        else:
            page.evaluate("(o) => window.scrollBy(0, parseInt(o, 10) || 0)", value(a, "value"))
    elif kind == "press":
        key = value(a, "key", "value")
        if not key:
            raise ValueError("press: missing key")
        if sel:
            page.locator(sel).press(key, timeout=tms)
        else:
            page.keyboard.press(key)
        base["key"] = key
    elif kind == "evaluate":
        script = value(a, "script")
        if not script:
            raise ValueError("evaluate: missing script")
        base["result"] = page.evaluate(script)
    elif kind == "screenshot":
        out = value(a, "outputFile")
        if not out:
            d = os.path.join(tempfile.gettempdir(), "kdeps-browser")
            os.makedirs(d, exist_ok=True)
            out = os.path.join(d, "screenshot-%d.png" % time.time_ns())
        else:
            os.makedirs(os.path.dirname(os.path.abspath(out)), exist_ok=True)
        if sel:
            page.locator(sel).screenshot(path=out, timeout=tms)
        else:
            page.screenshot(path=out, full_page=bool(a.get("fullPage")))
        base["file"] = out
    elif kind == "wait":
        target = value(a, "wait", "selector", "value")
        if not target:
            raise ValueError("wait: nothing to wait for")
        if re.fullmatch(r"(\d+(?:\.\d+)?)(ms|s|m)", target):
            time.sleep(seconds(target))
        else:
            page.locator(target).wait_for(timeout=tms)
        base["waited"] = target
    else:
        raise ValueError("unknown browser action: %r" % a.get("action"))
    base["success"] = True
    return base

results = []
with sync_playwright() as pw:
    browser = launch(pw)
    ctx_opts = {"viewport": {"width": int(viewport.get("width") or 1280),
                             "height": int(viewport.get("height") or 720)}}
    if arg("userAgent"):
        ctx_opts["user_agent"] = str(arg("userAgent"))
    if stealth:
        ctx_opts.update(locale="en-US", timezone_id="America/New_York", color_scheme="light")
    if state_file and os.path.exists(state_file):
        ctx_opts["storage_state"] = state_file
    context = browser.new_context(**ctx_opts)
    page = context.new_page()
    start = url
    if not start and url_file and os.path.exists(url_file):
        with open(url_file) as f:
            start = f.read().strip()
    try:
        if start:
            page.goto(start, timeout=tms)
        if wait_for:
            page.locator(wait_for).wait_for(timeout=tms)
        for i, a in enumerate(actions):
            try:
                results.append(run(page, a))
            except Exception as e:
                sys.exit("browser: action[%d] %r failed: %s" % (i, a.get("action"), e))
        text = ""
        if page.url != "about:blank":
            text = page.locator(extract).first.inner_text(timeout=tms)[:max_text]
    finally:
        if state_file:
            os.makedirs(state_dir, exist_ok=True)
            context.storage_state(path=state_file)
            with open(url_file, "w") as f:
                f.write(page.url)
    digest = hashlib.sha256(text.encode("utf-8")).hexdigest()
    title = page.title()
    changed = [] if since == digest else [{"url": page.url, "title": title, "text": text, "hash": digest}]
    print(json.dumps({"success": True, "url": page.url, "title": title, "text": text, "hash": digest,
                      "changed": changed, "sessionId": session_id, "actionResults": results}))
    browser.close()

Packages: playwright

Timeout: 600s

aliases:
  - browse
  - playwright
  - browser_ops
constraints: Each call starts a new browser process; a sessionId keeps cookies
  and the last page between calls. The engine's browser downloads on first use
  (needs network once). Per-step timeout 30s by default.
outputFormat: "JSON: success, url, title, text (the extract element, cut at
  maxText), hash (sha256 of text), changed ([] when hash equals since, else one
  item with url, title, text, hash), sessionId, actionResults"

Versions

VersionPublishedStatusSource
1.0.011/28/2026activeGitHub v1.0.0

Details

Author
kdeps
License
Apache-2.0
Latest Version
1.0.0
Published
11/28/2026

Tags

kdepstool