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
分析现有Web应用,识别路由、表单、服务器操作、处理器和模式中安全且用户可见的功能,然后实现第一方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
通过仅使用一个简短的任务提示和真实的……,投放多个Claude子代理来审计产品、SDK、文档站点或SKILL.md的开发者体验。
autobrowse
browserbase
通过自动研究循环实现自我改进的浏览器自动化。迭代执行浏览任务、读取追踪记录并优化导航技能…