functions

作者: browserbase

使用 Browserbase

npx skills add https://github.com/browserbase/skills --skill functions

Browserbase Functions

Deploy serverless browser automation using the official browse CLI.

Prerequisites

Get an API key from: https://browserbase.com/settings

export BROWSERBASE_API_KEY="your_api_key"

Creating a Function Project

1. Initialize

browse functions init my-function
cd my-function

This creates:

my-function/
├── package.json
├── index.ts        # Your function code
└── .env            # Add credentials here

2. Add Credentials to .env

echo "BROWSERBASE_API_KEY=$BROWSERBASE_API_KEY" >> .env

3. Install Dependencies

pnpm install

Function Structure

import { defineFn } from "@browserbasehq/sdk-functions";
import { chromium } from "playwright-core";

defineFn("my-function", async (context) => {
  const { session, params } = context;

  // Connect to browser
  const browser = await chromium.connectOverCDP(session.connectUrl);
  const page = browser.contexts()[0]!.pages()[0]!;

  // Your automation
  await page.goto(params.url || "https://example.com");
  const title = await page.title();

  // Return JSON-serializable result
  return { success: true, title };
});

Key objects:

  • context.session.connectUrl - CDP endpoint to connect Playwright
  • context.params - Input parameters from invocation

Development Workflow

1. Start Dev Server

browse functions dev index.ts

Server runs at http://127.0.0.1:14113

2. Test Locally

curl -X POST http://127.0.0.1:14113/v1/functions/my-function/invoke \
  -H "Content-Type: application/json" \
  -d '{"params": {"url": "https://news.ycombinator.com"}}'

3. Iterate

The dev server auto-reloads on file changes. Use console.log() for debugging - output appears in the terminal.

Deploying

browse functions publish index.ts

Output:

Function published successfully
Build ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Function ID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx

Save the Function ID - you need it to invoke.

Quick Reference

CommandDescription
browse functions init <name>Create new project
browse functions dev <file>Start local dev server
browse functions publish <file>Deploy to Browserbase

For invocation examples, common patterns, and troubleshooting, see REFERENCE.md.

來自 browserbase 的更多技能

optimize-agent-prompt
browserbase
透過Autobrowse風格的外部迴圈來建置並改進Browserbase Agent API示範:執行固定任務、收集Agent訊息與工作階段日誌、評分結果、修訂一條系統提示啟發式規則,並確認收斂。適用於建立Browserbase Agents示範或概念驗證、最佳化Agent系統提示、診斷不穩定的Agent執行,或將自動研究/自動瀏覽應用於Browserbase Agents API時。
add-webmcp
browserbase
分析現有的網頁應用程式,識別跨路由、表單、伺服器動作、處理器和架構中的安全使用者可見功能,然後實作第一方 WebMCP 工具,並使用 Stagehand 驗證探索和呼叫。當使用者要求讓程式碼庫具備代理程式就緒狀態、將網站功能公開為 WebMCP 工具,或直接將 WebMCP 新增至應用程式(而非從 URL 產生獨立的注入腳本)時使用。
browse
browserbase
使用 browse CLI 進行 Browserbase 瀏覽器自動化、Browserbase 雲端 API、Browserbase Functions、範本、網頁擷取/搜尋、診斷,以及 Browse.sh…
browse
browserbase
使用 browse CLI 進行 Browserbase 瀏覽器自動化、Browserbase 雲端 API、Browserbase Functions、模板、網頁擷取/搜尋、診斷,以及 Browse.sh…
browser-automation
browserbase
使用MCP工具自動化網頁瀏覽器操作。當使用者要求瀏覽網站、導覽網頁、從網站提取資料、擷取螢幕截圖等時使用。
functions
browserbase
使用官方 Browserbase Functions CLI 引導無伺服器瀏覽器自動化的部署。當使用者想要部署自動化以在…上執行時使用。
agent-experience
browserbase
審核產品、SDK、文檔網站或 SKILL.md 的開發者體驗,方法是投放多個 Claude 子代理,僅附上極簡任務提示和真實…
autobrowse
browserbase
透過自動研究循環實現自我改進的瀏覽器自動化。反覆執行瀏覽任務、讀取追蹤記錄,並持續提升導航技能…