Browser Automation with nstbrowser-ai-agent
Overview
This skill enables AI agents to control browsers using nstbrowser-ai-agent CLI with Nstbrowser integration. Nstbrowser provides advanced browser fingerprinting, profile management, and anti-detection capabilities for professional browser automation.
This tool requires Nstbrowser service to function. All browser operations are performed through Nstbrowser profiles, which provide:
- - Advanced browser fingerprinting and anti-detection
- Profile management with persistent sessions
- Proxy configuration per profile
- Batch operations on multiple profiles
- Tag and group organization for profile management
Prerequisites
Before using this tool, ensure you have the following:
1. Nstbrowser Client Installation
Nstbrowser client must be installed and running on your system.
- - Download from: https://www.nstbrowser.io/
- Install the client application
- Launch the Nstbrowser client
2. Nstbrowser Service Running
The Nstbrowser API service must be accessible:
- - Default endpoint: INLINECODE0
- Verify service is running using the CLI:
nstbrowser-ai-agent profile list
- - Expected response: List of profiles or empty list
3. API Key Configuration
Obtain your API key from the Nstbrowser dashboard and configure it:
Method 1: Config File (Recommended)
CODEBLOCK1
Method 2: Environment Variable
Set the NSTAPIKEY environment variable in your shell configuration file.
4. CLI Tool Installation
Install the nstbrowser-ai-agent CLI:
CODEBLOCK2
5. Verify Installation
Test your setup:
CODEBLOCK3
If you see your profiles or an empty list, your environment is configured correctly.
Quick Start
Get started in 5 minutes with these examples:
Option 1: Using Temporary Browser (Fastest)
For quick tests or one-time tasks:
CODEBLOCK4
Note: Temporary browsers don't save session state and are cleaned up after use.
Option 2: Using Profile (Recommended for Persistent Sessions)
For tasks that require saved sessions, cookies, or login state:
CODEBLOCK5
Expected Output:
- - Profile list shows your profiles with IDs and names
- Browser opens in headless mode
- Snapshot shows page structure with element refs (@e1, @e2, etc.)
- Session state persists across browser restarts
Core Concepts
Profiles
Profiles are the foundation of Nstbrowser automation. Each profile is an isolated browser environment that stores:
- - Browser Fingerprints: Canvas, WebGL, fonts, screen resolution, timezone
- Session Data: Cookies, localStorage, sessionStorage
- Login State: Persistent authentication across sessions
- Proxy Settings: Per-profile proxy configuration
- Browser Configuration: User agent, platform, language settings
Why use profiles?
- - Maintain separate identities for different tasks
- Preserve login sessions between automation runs
- Isolate cookies and data between different websites
- Configure different proxies for different regions
Profile Name vs ID
All profile commands support both profile NAME and profile ID:
Profile Name:
- - User-friendly, easier to remember
- Example:
my-profile, test-account, INLINECODE3 - Use when: Working interactively or in scripts with descriptive names
Profile ID:
- - UUID format, guaranteed uniqueness
- Example: INLINECODE4
- Use when: Scripting with multiple profiles or ensuring exact profile match
UUID Format Auto-Detection:
- - The system automatically detects UUID format in profile names
- If you provide a UUID-formatted string to
--profile, it's treated as a profile ID - This prevents accidental profile creation when you meant to use an ID
- Example:
--profile "86581051-fb0d-4c4a-b1e3-ebc1abd17174" is treated as profile ID
Resolution Priority:
- 1.
--profile flag (profile name or UUID auto-detected as ID) - Use once browser if no profile specified
Profile Resolution Logic:
When you specify a profile for a browser action:
- 1. Check running browsers - Uses existing browser if already running (earliest if multiple)
- Start browser - Starts the profile if it exists but isn't running
- Create profile - If profile NAME doesn't exist, creates it automatically
- Error - If profile ID doesn't exist, returns an error
- Once browser - If no profile specified, uses or creates temporary browser
Important: If multiple profiles have the same name, the earliest started browser will be used.
Sticky Sessions
Once you start a session with a profile, that session "locks" to that browser instance. Subsequent commands automatically reuse the same browser without repeating the --profile flag.
CODEBLOCK6
This makes automation scripts cleaner and reduces the need to specify the profile repeatedly.
Refs
Elements are identified by refs (e.g., @e1, @e2) from snapshots, making automation more reliable than CSS selectors.
CODEBLOCK7
Note: For modern web frameworks (React, Vue, Angular), CSS selectors may be more reliable than refs.
Configuration
Config File (Recommended)
Store configuration persistently in ~/.nst-ai-agent/config.json:
CODEBLOCK8
Configuration persists across sessions and takes priority over environment variables.
Environment Variables
Alternative to config file:
CODEBLOCK9
Priority: Config file > Environment variables > Defaults
Common Commands
Profile Management
List Profiles
CODEBLOCK10
Show Profile Details
CODEBLOCK11
Create Profile
CODEBLOCK12
Delete Profile
CODEBLOCK13
Browser Control
Start Browser
CODEBLOCK14
Stop Browser
CODEBLOCK15
List Running Browsers
CODEBLOCK16
Page Navigation
Open URL
CODEBLOCK17
Navigate
CODEBLOCK18
Page Inspection
Get Snapshot
CODEBLOCK19
Get Page Info
CODEBLOCK20
Take Screenshot
CODEBLOCK21
Element Interaction
Click
CODEBLOCK22
Fill Input
CODEBLOCK23
Type Text
CODEBLOCK24
Get Element Text
CODEBLOCK25
Wait Commands
Wait for Element
CODEBLOCK26
Wait for Time
CODEBLOCK27
Wait for Page Load
CODEBLOCK28
JavaScript Execution
Execute JavaScript
CODEBLOCK29
Proxy Management
Show Proxy
CODEBLOCK30
Update Proxy
CODEBLOCK31
Reset Proxy
CODEBLOCK32
Batch Proxy Operations
CODEBLOCK33
Workflow Examples
Pattern 1: Profile-based Automation
Use Case: Automate tasks that require persistent login sessions or cookies.
CODEBLOCK34
Pattern 2: Batch Profile Management
Use Case: Manage multiple profiles efficiently (update proxies, add tags, organize).
CODEBLOCK35
Pattern 3: Login and Scrape
Use Case: Log in to a website, navigate to data pages, and extract information.
CODEBLOCK36
Error Handling
Common Errors (by frequency)
1. "NSTAPIKEY is required"
Cause: API key not configured.
Solution:
CODEBLOCK37
Verify:
CODEBLOCK38
2. "Failed to connect to Nstbrowser"
Cause: Nstbrowser service not running or wrong endpoint.
Solution:
- 1. Check if NST agent is running:
nstbrowser-ai-agent nst status
- 2. Ensure Nstbrowser client is running
- If using custom host/port, configure:
CODEBLOCK40
Verify:
CODEBLOCK41
3. "Profile not found"
Cause: Specified profile doesn't exist.
Solution:
- 1. List available profiles:
nstbrowser-ai-agent profile list
- 2. Create a new profile:
nstbrowser-ai-agent profile create my-profile
- 3. Or use temporary browser:
CODEBLOCK44
Verify:
CODEBLOCK45
4. "Element not found" or "Action timed out"
Cause: Element ref is stale or page structure changed.
Solution:
- 1. Get fresh snapshot:
nstbrowser-ai-agent snapshot -i
- 2. Use CSS selectors instead of refs:
# Instead of: nstbrowser-ai-agent click @e1
# Use: nstbrowser-ai-agent click 'button[type="submit"]'
- 3. Inspect page elements:
CODEBLOCK48
Verify:
CODEBLOCK49
Ref System Limitations
The ref system (@e1, @e2, etc.) may not work reliably with modern web frameworks (Vue.js, React, Angular) due to dynamic DOM updates.
Workaround - Use CSS Selectors:
CODEBLOCK50
Command Reference
Profile Commands
- -
profile list - List all profiles - INLINECODE13 - List profiles with cursor pagination
- INLINECODE14 - Show profile details
- INLINECODE15 - Create new profile
- INLINECODE16 - Delete profile(s)
- INLINECODE17 - List all groups
- INLINECODE18 - Move profile(s) to group
- INLINECODE19 - Batch change group
- INLINECODE20 - Clear profile cache
- INLINECODE21 - Clear profile cookies
Proxy Commands
- -
profile proxy show <name-or-id> - Show proxy configuration - INLINECODE23 - Update proxy settings
- INLINECODE24 - Reset proxy settings
- INLINECODE25 - Batch update proxy
- INLINECODE26 - Batch reset proxy
Tag Commands
- -
profile tags list - List all tags - INLINECODE28 - Add tag to profile
- INLINECODE29 - Update profile tags
- INLINECODE30 - Clear profile tags
- INLINECODE31 - Batch create tags
- INLINECODE32 - Batch update tags
- INLINECODE33 - Batch clear tags
Browser Commands
- -
browser list - List running browsers - INLINECODE35 - Start browser with profile
- INLINECODE36 - Start temporary browser
- INLINECODE37 - Stop browser
- INLINECODE38 - Stop all browsers
- INLINECODE39 - Get browser pages list
- INLINECODE40 - Get debugger URL
- INLINECODE41 - Get CDP WebSocket URL
- INLINECODE42 - Get CDP URL for temporary browser
- INLINECODE43 - Connect and get CDP URL
- INLINECODE44 - Connect to temporary browser and get CDP URL
Navigation Commands
- -
open <url> - Navigate to URL - INLINECODE46 - Go back
- INLINECODE47 - Go forward
- INLINECODE48 - Reload page
Inspection Commands
- -
snapshot [-i] [-c] [-d <depth>] - Get page snapshot - INLINECODE50 - Get page title
- INLINECODE51 - Get current URL
- INLINECODE52 - Get element text
- INLINECODE53 - Take screenshot
- INLINECODE54 - Check if element is visible
Interaction Commands
- -
click <sel> - Click element - INLINECODE56 - Fill input
- INLINECODE57 - Type into element
- INLINECODE58 - Press key
- INLINECODE59 - Wait for element or time
Utility Commands
- -
eval <js> - Execute JavaScript - INLINECODE61 - Close browser
- INLINECODE62 - List active sessions
- INLINECODE63 - Check for available updates
- INLINECODE64 - Check if NST agent is running
- INLINECODE65 - Set configuration
- INLINECODE66 - Get configuration value
- INLINECODE67 - Show all configuration
JSON Output
All commands support --json flag for machine-readable output:
CODEBLOCK51
Best Practices
- 1. Use Profile Names: More readable than IDs for most use cases
- Leverage Sticky Sessions: No need to repeat
--profile flag once browser is running - Use Batch Operations: More efficient for multiple profiles
- Organize with Groups and Tags: Keep profiles organized
- Prefer CSS Selectors for Modern Apps: Refs may not work with Vue/React/Angular
- Wait Appropriately: Use
wait --load networkidle after navigation - Close Cleanly: Always close browser to save session state
- Handle Errors: Check command output and retry if needed
- Use Proxies Per Profile: Configure proxies for geo-targeting or privacy
- Keep Updated: Run
nstbrowser-ai-agent update check periodically
Updates
Automatic Update Checks
The CLI automatically checks for updates once every 24 hours and notifies you when a new version is available.
Disable automatic checks:
CODEBLOCK52
Manual Update Check
CODEBLOCK53
Updating to Latest Version
CODEBLOCK54
Deep-Dive Documentation
For more detailed information, see:
Profile creation, organization, and lifecycle |
|
references/proxy-configuration.md | Proxy setup, testing, and troubleshooting |
|
references/batch-operations.md | Efficient batch operations on multiple profiles |
|
references/troubleshooting.md | Common issues and diagnostic commands |
Ready-to-Use Templates
Batch proxy update for multiple profiles |
|
templates/automated-workflow.sh | Complete automation workflow example |
CODEBLOCK55
Notes
- - Nstbrowser is required: This tool only works with Nstbrowser service
- Profile name/ID support: All commands accept both names and IDs
- Auto-start: Browser automatically starts when using profile if not running
- Name resolution: Profile names are resolved to IDs automatically via API
- Sticky sessions: Profile persists across commands in the same session
- Profiles managed by Nstbrowser: Profiles are created and stored by Nstbrowser client
- Daemon auto-starts: Daemon starts on first command and persists between commands
- Session persistence: Session state is automatically saved to profiles when browser closes
- Temporary browsers: Use
browser start-once for disposable sessions that don't save state
CDP Integration
Get Chrome DevTools Protocol (CDP) WebSocket URLs to connect external tools:
CODEBLOCK56
Use cases:
- - Connect Puppeteer/Playwright to Nstbrowser-managed browsers
- Attach Chrome DevTools for debugging
- Integrate with custom CDP-based automation tools
- Monitor browser activity with external tools
使用 nstbrowser-ai-agent 进行浏览器自动化
概述
本技能使 AI 代理能够通过集成 Nstbrowser 的 nstbrowser-ai-agent CLI 来控制浏览器。Nstbrowser 为专业浏览器自动化提供高级浏览器指纹、配置文件管理和反检测功能。
此工具需要 Nstbrowser 服务才能运行。 所有浏览器操作均通过 Nstbrowser 配置文件执行,提供以下功能:
- - 高级浏览器指纹和反检测
- 具有持久会话的配置文件管理
- 每个配置文件的代理配置
- 对多个配置文件的批量操作
- 用于配置文件管理的标签和分组组织
前提条件
使用此工具前,请确保满足以下条件:
1. 安装 Nstbrowser 客户端
Nstbrowser 客户端必须已安装并在系统上运行。
- - 下载地址:https://www.nstbrowser.io/
- 安装客户端应用程序
- 启动 Nstbrowser 客户端
2. Nstbrowser 服务运行中
Nstbrowser API 服务必须可访问:
- - 默认端点:http://127.0.0.1:8848
- 使用 CLI 验证服务是否运行:
bash
nstbrowser-ai-agent profile list
3. API 密钥配置
从 Nstbrowser 仪表盘获取 API 密钥并进行配置:
方法 1:配置文件(推荐)
bash
nstbrowser-ai-agent config set key YOURAPIKEY
方法 2:环境变量
在 shell 配置文件中设置 NSTAPIKEY 环境变量。
4. CLI 工具安装
安装 nstbrowser-ai-agent CLI:
bash
使用 npx(无需安装)
npx nstbrowser-ai-agent --help
或全局安装
npm install -g nstbrowser-ai-agent
5. 验证安装
测试您的设置:
bash
检查 CLI 版本
nstbrowser-ai-agent --version
列出配置文件(验证 API 连接)
nstbrowser-ai-agent profile list
如果您看到配置文件列表或空列表,则环境配置正确。
快速入门
通过以下示例在 5 分钟内开始使用:
选项 1:使用临时浏览器(最快)
适用于快速测试或一次性任务:
bash
1. 启动临时浏览器
nstbrowser-ai-agent browser start-once
2. 打开网站
nstbrowser-ai-agent open https://example.com
3. 获取快照
nstbrowser-ai-agent snapshot -i
4. 关闭浏览器(自动清理)
nstbrowser-ai-agent close
注意: 临时浏览器不保存会话状态,使用后会被清理。
选项 2:使用配置文件(推荐用于持久会话)
适用于需要保存会话、Cookie 或登录状态的任务:
bash
1. 列出可用配置文件
nstbrowser-ai-agent profile list
2. 创建新配置文件(如果需要)
nstbrowser-ai-agent profile create my-profile
3. 使用配置文件打开浏览器(如果未运行则自动启动)
nstbrowser-ai-agent open https://example.com
4. 与页面交互
nstbrowser-ai-agent snapshot -i
nstbrowser-ai-agent click @e1
5. 关闭浏览器(会话保存到配置文件)
nstbrowser-ai-agent close
预期输出:
- - 配置文件列表显示带有 ID 和名称的配置文件
- 浏览器以无头模式打开
- 快照显示带有元素引用(@e1、@e2 等)的页面结构
- 会话状态在浏览器重启后持续存在
核心概念
配置文件
配置文件是 Nstbrowser 自动化的基础。 每个配置文件都是一个隔离的浏览器环境,存储以下内容:
- - 浏览器指纹:Canvas、WebGL、字体、屏幕分辨率、时区
- 会话数据:Cookie、localStorage、sessionStorage
- 登录状态:跨会话的持久身份验证
- 代理设置:每个配置文件的代理配置
- 浏览器配置:用户代理、平台、语言设置
为什么使用配置文件?
- - 为不同任务维护独立身份
- 在自动化运行之间保留登录会话
- 隔离不同网站之间的 Cookie 和数据
- 为不同区域配置不同的代理
配置文件名称与 ID
所有配置文件命令都支持配置文件名称和 ID:
配置文件名称:
- - 用户友好,易于记忆
- 示例:my-profile、test-account、production-bot
- 使用场景:交互式操作或使用描述性名称的脚本
配置文件 ID:
- - UUID 格式,保证唯一性
- 示例:86581051-fb0d-4c4a-b1e3-ebc1abd17174
- 使用场景:使用多个配置文件的脚本或确保精确匹配
UUID 格式自动检测:
- - 系统会自动检测配置文件名称中的 UUID 格式
- 如果您向 --profile 提供 UUID 格式的字符串,则将其视为配置文件 ID
- 这可以防止在您打算使用 ID 时意外创建配置文件
- 示例:--profile 86581051-fb0d-4c4a-b1e3-ebc1abd17174 被视为配置文件 ID
解析优先级:
- 1. --profile 标志(配置文件名称或自动检测为 ID 的 UUID)
- 如果未指定配置文件,则使用一次性浏览器
配置文件解析逻辑:
当您为浏览器操作指定配置文件时:
- 1. 检查运行中的浏览器 - 如果已在运行,则使用现有浏览器(如果有多个,则使用最早启动的)
- 启动浏览器 - 如果配置文件存在但未运行,则启动它
- 创建配置文件 - 如果配置文件名称不存在,则自动创建
- 错误 - 如果配置文件 ID 不存在,则返回错误
- 一次性浏览器 - 如果未指定配置文件,则使用或创建临时浏览器
重要提示: 如果多个配置文件具有相同名称,将使用最早启动的浏览器。
粘性会话
一旦您使用配置文件启动会话,该会话就会锁定到该浏览器实例。后续命令会自动重用同一浏览器,无需重复使用 --profile 标志。
bash
第一个命令:将会话链接到配置文件
nstbrowser-ai-agent --profile my-profile open https://example.com
后续命令:自动保持在 my-profile 中
nstbrowser-ai-agent snapshot -i
nstbrowser-ai-agent click @e1
nstbrowser-ai-agent fill @e2 data
这使得自动化脚本更简洁,并减少了重复指定配置文件的需要。
引用
元素通过快照中的引用(例如 @e1、@e2)进行标识,使自动化比 CSS 选择器更可靠。
bash
获取带引用的快照
nstbrowser-ai-agent snapshot -i
输出显示带有引用的元素:
@e1 button Submit
@e2 textbox Email
@e3 textbox Password
使用引用进行交互
nstbrowser-ai-agent fill @e2 user@example.com
nstbrowser-ai-agent fill @e3 password
nstbrowser-ai-agent click @e1
注意: 对于现代 Web 框架(React、Vue、Angular),CSS 选择器可能比引用更可靠。
配置
配置文件(推荐)
将配置持久存储在 ~/.nst-ai-agent/config.json 中:
bash
设置 API 密钥(必需)
nstbrowser-ai-agent config set key YOUR
APIKEY
可选:设置自定义主机
nstbrowser-ai-agent config set host api.example.com
可选:设置自定义端口
nstbrowser-ai-agent config set port 9000
查看所有配置
nstbrowser-ai-agent config show
获取特定值
nstbrowser-ai-agent config get key
配置在会话之间持久存在,并优先于环境变量。
环境变量
配置文件的替代方案:
bash
Nstbrowser API 凭据(如果未使用配置文件,则为必需)
在环境中设置 NSTAPIKEY
可选:Nstbrowser API 端点
如果使用自定义端点,请设置 NSTHOST 和 NSTPORT
可选:为每个命令指定配置文件
nstbrowser-ai-agent open https://example.com --profile my-profile
优先级: 配置文件 > 环境变量 > 默认值
常用命令
配置文件管理
列出配置文件
bash
列出所有配置文件
nstbrowser-ai-agent profile list