@pi-stef/web

extensionmaintained

Pi extension for no-key web search, URL fetch, rendered scraping, browser sessions, login flows, and CloakBrowser-backed page access.

by · v0.3.5 · published 4d ago

$ pi install npm:@pi-stef/web
downloads/mo
2.4K
stars
9
last push
1d ago
open issues
0

Signals

license: MITtestspi manifest: missinginstall size: —deps: 0peer deps: 0

Download trend

5.4K downloads · last 12 weeks (weekly)

README

SF Web Access

@pi-stef/web provides no-key web search, URL fetch, browser automation, login sessions, and CloakBrowser-backed page rendering as a Pi extension.

Installation

pi install npm:@pi-stef/web

For project-local install:

pi install -l npm:@pi-stef/web

After installation, verify runtime dependencies:

pnpm --filter web check-runtime

Install the CloakBrowser browser binary when needed:

pnpm --filter web install-browser

Contents

Natural Language Usage

The agent understands natural-language requests and routes them to the correct tool. Examples:

Search the web:

"Search for current browser automation options and summarize the top sources."
"What's the latest news on DFW weather?"
"Find recent articles about Rust web frameworks."

The agent calls sf_web_search.

Fetch a specific URL:

"Fetch this URL as markdown: https://example.com/docs"
"Read the content of https://example.com and summarize it."
"Use the browser to fetch https://example.com (it needs JavaScript)."

The agent calls sf_web_fetch. Asking to "use the browser" forces mode='browser'.

Run a browser flow:

"Use the browser to go to google.com, search for 'espresso machines', and extract the results."
"Open walmart.com, search for 'laptop deals', and click the first result."
"Navigate to example.com/login, fill in the username and password, and submit."

The agent calls sf_web_flow.

Create a login session:

"Log into https://example.com using my credentials."
"Create a browser login session for the staging site."

The agent calls sf_web_login.

Manage sessions:

"List my browser sessions."
"Clear the 'staging' browser session profile."

The agent calls sf_web_session.

Slash Commands

Slash commands inject a prompt into the agent conversation. The agent then calls the corresponding tool.

CommandArgsExample
/sf-web-search<query>/sf-web-search DFW weather forecast
/sf-web-fetch<url>/sf-web-fetch https://example.com/docs
/sf-web-flow<instruction>/sf-web-flow go to google.com and search for Rust
/sf-web-login<url>/sf-web-login https://example.com/login
/sf-web-session[action] [name]/sf-web-session list
/sf-webstatus/sf-web status

If /sf-web-search is already registered by another package, the extension falls back to /sf-search.

Tools

All tools use the sf_web_ prefix to avoid collisions with other Pi extensions.

sf_web_search

Search the web through a no-key provider cascade.

ParameterTypeRequiredDescription
querystringyesSearch query
maxResultsinteger (1-20)noMaximum results to return (default: 10)
providersstring[]noOrdered provider list: searxng, searxng-html, duckduckgo, google, bing
searxngUrlstringnoSearXNG instance URL override
headlessbooleannoHeadless browser mode (default: true)
profilestringnoBrowser profile name for browser-backed providers

sf_web_fetch

Fetch a specific URL. Defaults to fast HTTP; falls back to CloakBrowser for JS-heavy pages.

ParameterTypeRequiredDescription
urlstringyesURL to fetch
formatstringnoOutput format: markdown, text, html, json, raw (default: markdown)
modestringnoFetch mode: auto, fast, browser (default: auto)
headlessbooleannoHeadless browser mode (default: true)
profilestringnoBrowser profile name for rendered fetches
screenshotbooleannoCapture a screenshot when browser mode is used
selectorstringnoCSS selector to extract from HTML pages

mode values:

  • auto — tries fast HTTP first, falls back to browser if JS-heavy or blocked
  • fast — HTTP only, no browser fallback
  • browser — always uses CloakBrowser rendering

sf_web_flow

Automate multi-step browser interactions in CloakBrowser. Accepts natural-language instructions or structured step arrays.

ParameterTypeRequiredDescription
instructionstringnoNatural-language flow instruction
stepsarraynoStructured step array (see below)
headlessbooleannoHeadless browser mode (default: true)
profilestringnoBrowser profile name

Either instruction or steps must be provided.

Natural-language instruction examples:

"go to google.com and search for espresso machines"
"open example.com then click 'About' then wait 2s"
"navigate to https://example.com/login; type 'user@example.com' in input[name='email']; press Enter"

Structured step actions:

ActionFieldsDescription
goto / navigate / openurlNavigate to URL
clickselector, or role + name, or textClick an element
type / filltext, optional selectorType text into an input
press / keypress / keykey, optional selectorPress a keyboard key
waitmsWait in milliseconds (0-120000)
screenshotpathCapture screenshot to file
extractselector, optional countExtract text content from matching elements

sf_web_login

Create or refresh a named CloakBrowser login profile. Credentials come from environment variables.

ParameterTypeRequiredDescription
urlstringyesLogin page URL
profilestringnoBrowser profile name (default: default)
interactivebooleannoOpen a headed browser for manual login
interactiveWaitMsinteger (1000-600000)noWait time for interactive login
usernameEnvstringnoEnv var name containing username (default: SF_WEB_USERNAME)
passwordEnvstringnoEnv var name containing password (default: SF_WEB_PASSWORD)
headlessbooleannoHeadless browser mode (default: true)

sf_web_session

List, inspect, locate, or clear CloakBrowser session profiles.

ParameterTypeRequiredDescription
actionstringnolist, inspect, locate, or clear (default: list)
profilestringnoProfile name (default: default)
yesbooleannoConfirm destructive clear action

Configuration

Configuration is loaded from four layers, merged with later layers overriding earlier:

  1. Hardcoded defaults
  2. Config file: ~/.pi/web/config.json (or $SF_WEB_CONFIG)
  3. Environment variables: SF_WEB_*
  4. Runtime parameters: passed directly to tool calls

Config File

Location: ~/.pi/web/config.json (override with SF_WEB_CONFIG).

{
  "maxResults": 10,
  "searchProviders": ["searxng", "duckduckgo", "google", "bing"],
  "searxngUrl": "https://search.example.com",
  "allowPrivateNetworks": false,
  "fetchMaxBytes": 2097152,
  "fetchTimeoutMs": 15000,
  "maxBytes": 51200,
  "maxLines": 2000,
  "outputDir": "/tmp/sf-web",
  "profilesDir": "~/.pi/web/profiles",
  "userAgent": "Mozilla/5.0 ...",
  "browserFingerprintSeed": "42",
  "browserHumanPreset": "default",
  "browserLocale": "en-US",
  "browserTimezone": "America/New_York",
  "browserProxy": "socks5://proxy:1080",
  "browserGeoip": false
}

Environment Variables

Env VarConfig KeyTypeDefaultDescription
SF_WEB_CONFIGstring~/.pi/web/config.jsonConfig file path
SF_WEB_SEARXNG_URLsearxngUrlstringSearXNG instance URL
SF_WEB_SEARCH_PROVIDERSsearchProvidersCSVsearxng,duckduckgo,google,bingOrdered search providers
SF_WEB_MAX_RESULTSmaxResultsinteger10Default max search results
SF_WEB_MAX_BYTESmaxBytesinteger51200Max tool output bytes
SF_WEB_MAX_LINESmaxLinesinteger2000Max tool output lines
SF_WEB_FETCH_MAX_BYTESfetchMaxBytesinteger2097152Max HTTP body bytes
SF_WEB_FETCH_TIMEOUT_MSfetchTimeoutMsinteger15000HTTP fetch timeout (ms)
SF_WEB_ALLOW_PRIVATE_NETWORKSallowPrivateNetworksbooleanfalseAllow private/loopback IPs
SF_WEB_OUTPUT_DIRoutputDirstring$TMPDIR/sf-webOutput file directory
SF_WEB_PROFILES_DIRprofilesDirstring~/.pi/web/profilesBrowser profiles directory
SF_WEB_USER_AGENTuserAgentstringChrome 124 UAHTTP user-agent (fast fetch only)
SF_WEB_BROWSER_FINGERPRINT_SEEDbrowserFingerprintSeedstringautoFingerprint seed (positive integer)
SF_WEB_BROWSER_HUMAN_PRESETbrowserHumanPresetstringdefault or careful
SF_WEB_BROWSER_LOCALEbrowserLocalestringBrowser locale (e.g., en-US)
SF_WEB_BROWSER_TIMEZONEbrowserTimezonestringBrowser timezone (e.g., America/New_York)
SF_WEB_BROWSER_PROXYbrowserProxystringProxy URL (http:, https:, or socks5:)
SF_WEB_BROWSER_GEOIPbrowserGeoipbooleanEnable GeoIP (requires CloakBrowser support)
SF_WEB_USERNAMEstringDefault username for sf_web_login
SF_WEB_PASSWORDstringDefault password for sf_web_login
SF_WEB_SENSITIVE_QUERY_KEYSsensitiveQueryKeysCSVbuilt-in listAdditional URL params to redact from errors

No-Key Search Setup

Search works without API keys by default. Configure a SearXNG instance for best results:

export SF_WEB_SEARXNG_URL="https://search.example.com"

Provider cascade:

SearXNG JSON → SearXNG HTML → DuckDuckGo HTML/Lite → Google (browser) → Bing (browser)

Each provider is tried in order. The first to return results wins. Google and Bing require CloakBrowser and are last-resort fallbacks.

Browser Identity

Browser mode uses CloakBrowser for fingerprint management. Named profiles get a stable derived fingerprint seed.

For first-run challenges, use headed mode once, complete the challenge manually, then reuse the profile in headless mode.

Browser hardening is config-only (not tool parameters):

SettingConfig KeyNotes
Fingerprint seedbrowserFingerprintSeedPositive integer; auto-derived from profile name if omitted
Human presetbrowserHumanPresetdefault or careful
LocalebrowserLocalee.g., en-US
TimezonebrowserTimezonee.g., America/New_York
ProxybrowserProxyhttp:, https:, or socks5: URL
GeoIPbrowserGeoipRequires CloakBrowser's optional GeoIP support

Security Notes

  • Only http: and https: URLs are allowed.
  • Private, loopback, link-local, multicast, and reserved IP ranges are blocked by default.
  • Fast fetch re-validates redirects before reading the body.
  • Browser profiles contain cookies and session tokens. Clear them when no longer needed.
  • sf_web_login does not accept raw passwords. Use interactive login or environment variable names.

Browser Tests

Real browser tests are skipped by default. Run them when intentionally testing CloakBrowser:

SF_WEB_RUN_BROWSER_TESTS=1 pnpm exec vitest run packages/web/tests/browserSmoke.test.ts
SF_WEB_RUN_BROWSER_TESTS=1 pnpm exec vitest run packages/web/tests/tools.e2e.test.ts

License

Runtime dependencies:

PackagePurposeLicense
cloakbrowserCloakHQ browser launcher/runtimeMIT
playwright-coreBrowser automation APIApache-2.0
defuddleClean article extractionMIT
@mozilla/readabilityReadability fallback extractionApache-2.0
turndownHTML to Markdown conversionMIT
jsdomServer-side DOM for extractionMIT
@sinclair/typeboxJSON schema type builderMIT