wuying-agentbay-sdk 0.10.2 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (108) hide show
  1. package/dist/chunk-BVWUCG4J.mjs +3402 -0
  2. package/dist/chunk-BVWUCG4J.mjs.map +1 -0
  3. package/dist/chunk-SL5GCAQE.cjs +3393 -0
  4. package/dist/chunk-SL5GCAQE.cjs.map +1 -0
  5. package/dist/index.cjs +4623 -3978
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.mts +3934 -1964
  8. package/dist/index.d.ts +3934 -1964
  9. package/dist/index.mjs +4601 -3956
  10. package/dist/index.mjs.map +1 -1
  11. package/dist/key-normalizer-AF7APGQZ.cjs +136 -0
  12. package/dist/key-normalizer-AF7APGQZ.cjs.map +1 -0
  13. package/dist/key-normalizer-QDBRLFHF.mjs +145 -0
  14. package/dist/key-normalizer-QDBRLFHF.mjs.map +1 -0
  15. package/dist/model-CNCGFWJH.cjs +200 -0
  16. package/dist/model-CNCGFWJH.cjs.map +1 -0
  17. package/dist/model-LGWQJWKQ.mjs +209 -0
  18. package/docs/api/README.md +26 -0
  19. package/docs/api/browser-use/browser.md +177 -0
  20. package/docs/api/browser-use/extension.md +284 -0
  21. package/docs/api/codespace/code.md +77 -0
  22. package/docs/api/common-features/advanced/agent.md +84 -0
  23. package/docs/api/common-features/advanced/oss.md +221 -0
  24. package/docs/api/common-features/basics/agentbay.md +277 -0
  25. package/docs/api/common-features/basics/command.md +83 -0
  26. package/docs/api/common-features/basics/context-manager.md +149 -0
  27. package/docs/api/common-features/basics/context-sync.md +51 -0
  28. package/docs/api/common-features/basics/context.md +348 -0
  29. package/docs/api/common-features/basics/filesystem.md +499 -0
  30. package/docs/api/common-features/basics/logging.md +77 -0
  31. package/docs/api/common-features/basics/session.md +542 -0
  32. package/docs/api/computer-use/computer.md +786 -0
  33. package/docs/api/mobile-use/mobile.md +395 -0
  34. package/docs/examples/README.md +332 -0
  35. package/docs/examples/basic-usage.ts +86 -0
  36. package/docs/examples/browser-use/browser/README.md +356 -0
  37. package/docs/examples/browser-use/browser/basic-usage.ts +136 -0
  38. package/docs/examples/browser-use/browser/browser-command-args.ts +117 -0
  39. package/docs/examples/browser-use/browser/browser-context-cookie-persistence.ts +348 -0
  40. package/docs/examples/browser-use/browser/browser-fingerprint-basic-usage.ts +121 -0
  41. package/docs/examples/browser-use/browser/browser-fingerprint-construct.ts +114 -0
  42. package/docs/examples/browser-use/browser/browser-fingerprint-local-sync.ts +98 -0
  43. package/docs/examples/browser-use/browser/browser-fingerprint-persistence.ts +242 -0
  44. package/docs/examples/browser-use/browser/browser-proxies.ts +149 -0
  45. package/docs/examples/browser-use/browser/browser-type-example.ts +266 -0
  46. package/docs/examples/browser-use/browser/browser-viewport.ts +129 -0
  47. package/docs/examples/browser-use/browser/call_for_user_jd.ts +184 -0
  48. package/docs/examples/browser-use/browser/captcha_tongcheng.ts +151 -0
  49. package/docs/examples/browser-use/browser/run-2048.ts +209 -0
  50. package/docs/examples/browser-use/browser/run-sudoku.ts +150 -0
  51. package/docs/examples/browser-use/browser/screenshot-example.ts +132 -0
  52. package/docs/examples/browser-use/extension-example/README.md +252 -0
  53. package/docs/examples/browser-use/extension-example/extension-example.ts +381 -0
  54. package/docs/examples/codespace/automation/automation-example.ts +322 -0
  55. package/docs/examples/common-features/advanced/agent-module-example/README.md +40 -0
  56. package/docs/examples/common-features/advanced/agent-module-example.ts +66 -0
  57. package/docs/examples/common-features/advanced/archive-upload-mode-example/README.md +212 -0
  58. package/docs/examples/common-features/advanced/archive-upload-mode-example/archive-upload-mode-example.ts +213 -0
  59. package/docs/examples/common-features/advanced/vpc-session-example/README.md +47 -0
  60. package/docs/examples/common-features/advanced/vpc-session-example.ts +106 -0
  61. package/docs/examples/common-features/basics/archive-upload-mode-example/README.md +236 -0
  62. package/docs/examples/common-features/basics/archive-upload-mode-example/main.ts +236 -0
  63. package/docs/examples/common-features/basics/command-example/README.md +47 -0
  64. package/docs/examples/common-features/basics/command-example/command-example.ts +153 -0
  65. package/docs/examples/common-features/basics/context-management/README.md +55 -0
  66. package/docs/examples/common-features/basics/context-management/context-management.ts +140 -0
  67. package/docs/examples/common-features/basics/data-persistence/README.md +129 -0
  68. package/docs/examples/common-features/basics/data-persistence/context-sync-demo.md +144 -0
  69. package/docs/examples/common-features/basics/data-persistence/context-sync-demo.ts +275 -0
  70. package/docs/examples/common-features/basics/data-persistence/data-persistence.ts +259 -0
  71. package/docs/examples/common-features/basics/data-persistence/recycle-policy-example.ts +294 -0
  72. package/docs/examples/common-features/basics/filesystem-example/README.md +57 -0
  73. package/docs/examples/common-features/basics/filesystem-example/filesystem-example.ts +164 -0
  74. package/docs/examples/common-features/basics/filesystem-example/filesystem-filetransfer-example.ts +153 -0
  75. package/docs/examples/common-features/basics/filesystem-example/watch-directory-example.ts +168 -0
  76. package/docs/examples/common-features/basics/get/README.md +136 -0
  77. package/docs/examples/common-features/basics/get/main.ts +79 -0
  78. package/docs/examples/common-features/basics/list_sessions/README.md +54 -0
  79. package/docs/examples/common-features/basics/list_sessions/main.ts +258 -0
  80. package/docs/examples/common-features/basics/mcp_tool_direct_call/README.md +142 -0
  81. package/docs/examples/common-features/basics/mcp_tool_direct_call/main.ts +135 -0
  82. package/docs/examples/common-features/basics/session-creation/README.md +28 -0
  83. package/docs/examples/common-features/basics/session-creation/session-creation.ts +295 -0
  84. package/docs/examples/common-features/basics/session-pause-resume/README.md +53 -0
  85. package/docs/examples/common-features/basics/session-pause-resume/session-pause-resume.ts +237 -0
  86. package/docs/examples/mobile-use/mobile-get-adb-url/README.md +92 -0
  87. package/docs/examples/mobile-use/mobile-get-adb-url/index.ts +80 -0
  88. package/docs/examples/mobile-use/mobile-get-adb-url/package-lock.json +279 -0
  89. package/docs/examples/mobile-use/mobile-get-adb-url/package.json +18 -0
  90. package/docs/examples/mobile-use/mobile-simulate-basic-usage.ts +202 -0
  91. package/docs/examples/mobile-use/mobile-simulate-with-ctx.ts +170 -0
  92. package/package.json +19 -12
  93. package/dist/application-KZWXH46T.mjs +0 -17
  94. package/dist/application-LMA7KSRH.cjs +0 -8
  95. package/dist/application-LMA7KSRH.cjs.map +0 -1
  96. package/dist/chunk-BQNGKBQF.mjs +0 -386
  97. package/dist/chunk-BQNGKBQF.mjs.map +0 -1
  98. package/dist/chunk-IOVGAAJL.cjs +0 -558
  99. package/dist/chunk-IOVGAAJL.cjs.map +0 -1
  100. package/dist/chunk-UF2TC2R4.mjs +0 -567
  101. package/dist/chunk-UF2TC2R4.mjs.map +0 -1
  102. package/dist/chunk-X6MS7Z5L.cjs +0 -377
  103. package/dist/chunk-X6MS7Z5L.cjs.map +0 -1
  104. package/dist/window-DH37ZDD5.mjs +0 -17
  105. package/dist/window-DH37ZDD5.mjs.map +0 -1
  106. package/dist/window-U7N3H735.cjs +0 -8
  107. package/dist/window-U7N3H735.cjs.map +0 -1
  108. /package/dist/{application-KZWXH46T.mjs.map → model-LGWQJWKQ.mjs.map} +0 -0
@@ -0,0 +1,150 @@
1
+ /**
2
+ * Example demonstrating AIBrowser capabilities with AgentBay SDK.
3
+ * This example shows how to use PageUseAgent to run sudoku game, including:
4
+ * - Create AIBrowser session
5
+ * - Use playwright to connect to AIBrowser instance through CDP protocol
6
+ * - Utilize PageUseAgent to run sudoku game
7
+ */
8
+
9
+ import { AgentBay, CreateSessionParams,BrowserOption, ExtractOptions, ActOptions } from 'wuying-agentbay-sdk';
10
+
11
+ import { chromium } from 'playwright';
12
+
13
+ class SudokuBoard {
14
+ board: number[][] = [];
15
+ }
16
+
17
+ class SudokuSolution {
18
+ solution: number[][] = [];
19
+ }
20
+
21
+ function formatBoardForLlm(board: number[][]): string {
22
+ return board.map(row => ` [${row.join(', ')}]`).join('\n');
23
+ }
24
+
25
+ async function main() {
26
+ // Get API key from environment variable
27
+ const apiKey = process.env.AGENTBAY_API_KEY;
28
+ if (!apiKey) {
29
+ console.log("Error: AGENTBAY_API_KEY environment variable not set");
30
+ return;
31
+ }
32
+
33
+ // Initialize AgentBay client
34
+ console.log("Initializing AgentBay client...");
35
+ const agentBay = new AgentBay({ apiKey });
36
+
37
+ // Create a session
38
+ console.log("Creating a new session...");
39
+ const params: CreateSessionParams = {
40
+ imageId: "browser_latest",
41
+ };
42
+ const sessionResult = await agentBay.create(params);
43
+
44
+ if (sessionResult.success) {
45
+ const session = sessionResult.session;
46
+ console.log(`Session created with ID: ${session.sessionId}`);
47
+
48
+ if (await session.browser.initializeAsync({} as BrowserOption)) {
49
+ console.log("Browser initialized successfully");
50
+ const endpointUrl = await session.browser.getEndpointUrl();
51
+ console.log("endpoint_url =", endpointUrl);
52
+
53
+ const browser = await chromium.connectOverCDP(endpointUrl);
54
+ try {
55
+ const context = browser.contexts()[0]
56
+ const page = await context.newPage();
57
+ console.log("🌐 Navigating to Sudoku site...");
58
+ const url = "https://widget.websudoku.com/";
59
+ await page.goto(url);
60
+ await page.waitForSelector("#puzzle_grid", { timeout: 10000 });
61
+
62
+ // 1. Extract the board
63
+ let success = false;
64
+ let board: number[][] = [];
65
+
66
+ while (!success) {
67
+ console.log("📊 Extracting sudoku board...");
68
+ const options: ExtractOptions<SudokuBoard> = {
69
+ instruction: "Extract the current sudoku board as a 9x9 array. Each cell should be a number (1-9) if filled, or 0 if empty.",
70
+ schema: SudokuBoard,
71
+ use_text_extract: false
72
+ };
73
+
74
+ const [extractSuccess, boardObjs] = await session.browser.agent.extract(options, page);
75
+ if (extractSuccess && boardObjs.length > 0) {
76
+ success = true;
77
+ board = boardObjs[0].board;
78
+ } else {
79
+ console.log("❌ Failed to extract sudoku board, retry extracting");
80
+ await new Promise(resolve => setTimeout(resolve, 3000));
81
+ }
82
+ }
83
+
84
+ console.log("Current Board:\n" + board.map(row => row.join(' ')).join('\n'));
85
+ const originalBoard = board.map(row => [...row]);
86
+
87
+ // 2. Solve the sudoku
88
+ const solutionOptions: ExtractOptions<SudokuSolution> = {
89
+ instruction: `You are an expert sudoku solver. Given the following sudoku board as a 9x9 array (0 means empty), solve the sudoku and return the completed 9x9 array as 'solution'.
90
+
91
+ Sudoku rules:
92
+ - Each row must contain the digits 1-9 with no repeats.
93
+ - Each column must contain the digits 1-9 with no repeats.
94
+ - Each of the nine 3x3 subgrids must contain the digits 1-9 with no repeats.
95
+ - Only fill in the cells that are 0.
96
+ - The solution must be unique and valid.
97
+
98
+ board = [
99
+ ${formatBoardForLlm(board)}
100
+ ]
101
+
102
+ Return:
103
+ {
104
+ solution: number[][] // 9x9, all filled, valid sudoku
105
+ }`,
106
+ schema: SudokuSolution,
107
+ use_text_extract: false
108
+ };
109
+
110
+ const [solutionSuccess, solutionObjs] = await session.browser.agent.extract(solutionOptions, page);
111
+ if (!solutionSuccess || solutionObjs.length === 0) {
112
+ console.log("❌ Failed to solve sudoku");
113
+ return;
114
+ }
115
+
116
+ const solution = solutionObjs[0].solution;
117
+ console.log("Solved Board:\n" + solution.map((row:any) => row.join(' ')).join('\n'));
118
+
119
+ // 3. Fill the solution
120
+ for (let row = 0; row < 9; row++) {
121
+ for (let col = 0; col < 9; col++) {
122
+ if (originalBoard[row][col] === 0) {
123
+ const inputId = `f${col}${row}`;
124
+ console.log(`Type '${solution[row][col]}' into the cell with id '${inputId}'`);
125
+
126
+ // Use the act method for natural language action
127
+ const actOptions: ActOptions = {
128
+ action: `Enter '${solution[row][col]}' into the input element where the attribute id is exactly '${inputId}' (for example, if id='f53', you must match the full string 'f53', not just the number 53; do not split or extract numbers from the id)`
129
+ };
130
+
131
+ await session.browser.agent.act(actOptions, page);
132
+ await new Promise(resolve => setTimeout(resolve, 500));
133
+ }
134
+ }
135
+ }
136
+
137
+ console.log("✅ Finished! The board has been solved and filled in the browser.");
138
+
139
+ } catch (error) {
140
+ console.log(`❌ Error in game loop: ${error}`);
141
+ }
142
+ } else {
143
+ console.log("Failed to initialize browser");
144
+ }
145
+ }
146
+ }
147
+
148
+ if (require.main === module) {
149
+ main().catch(console.error);
150
+ }
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Example demonstrating screenshot capabilities with AgentBay SDK (TypeScript).
3
+ * This example shows how to capture screenshots using direct Playwright integration.
4
+ *
5
+ * Features demonstrated:
6
+ * - Creating a browser session with AgentBay
7
+ * - Using Playwright to connect to the browser instance
8
+ * - Taking screenshots using direct Playwright integration (Uint8Array data)
9
+ * - Saving screenshots to local files
10
+ * - Customizing screenshot options (full page, image format, quality)
11
+ */
12
+
13
+ import { AgentBay } from 'wuying-agentbay-sdk';
14
+ import type { CreateSessionParams } from 'wuying-agentbay-sdk';
15
+ import { chromium } from 'playwright';
16
+ import { writeFile } from 'fs/promises';
17
+
18
+ async function main() {
19
+ // Get API key from environment variable
20
+ const apiKey = process.env.AGENTBAY_API_KEY;
21
+ if (!apiKey) {
22
+ console.error("Error: AGENTBAY_API_KEY environment variable not set");
23
+ return;
24
+ }
25
+
26
+ // Initialize AgentBay client
27
+ console.log("Initializing AgentBay client...");
28
+ const agentBay = new AgentBay({ apiKey });
29
+
30
+ // Create a session
31
+ console.log("Creating a new session...");
32
+ const params: CreateSessionParams = {
33
+ imageId: "browser_latest",
34
+ };
35
+ const sessionResult = await agentBay.create(params);
36
+
37
+ if (!sessionResult.success) {
38
+ console.error(`Failed to create session: ${sessionResult.errorMessage}`);
39
+ return;
40
+ }
41
+
42
+ const session = sessionResult.session;
43
+ console.log(`Session created with ID: ${session.sessionId}`);
44
+
45
+ try {
46
+ // Initialize the browser
47
+ const success = await session.browser.initializeAsync({});
48
+ if (!success) {
49
+ console.error("Failed to initialize browser");
50
+ return;
51
+ }
52
+
53
+ console.log("Browser initialized successfully");
54
+
55
+ // Get the browser endpoint and connect with Playwright
56
+ const endpointUrl = await session.browser.getEndpointUrl();
57
+ console.log(`Endpoint URL: ${endpointUrl}`);
58
+
59
+ // Connect with Playwright
60
+ const browser = await chromium.connectOverCDP(endpointUrl);
61
+ const context = browser.contexts()[0];
62
+ const page = await context.newPage();
63
+
64
+ // Navigate to a website
65
+ await page.goto("https://www.aliyun.com");
66
+ console.log("✅ Navigated to website");
67
+
68
+ // Take a simple screenshot (returns Uint8Array data)
69
+ // Note: In the current implementation, the screenshot method is a placeholder
70
+ // In a real implementation, this would capture the actual screenshot
71
+ console.log("📸 Taking screenshot...");
72
+
73
+ // This is a placeholder - in a real implementation, this would return actual screenshot data
74
+ // const screenshotData = await session.browser.screenshot(page);
75
+ // console.log(`✅ Browser screenshot captured (${screenshotData.length} bytes)`);
76
+
77
+ // Save the screenshot to a file
78
+ // await writeFile("browser_screenshot.png", Buffer.from(screenshotData));
79
+ // console.log("✅ Browser screenshot saved as browser_screenshot.png");
80
+
81
+ // Take a full page screenshot with custom options
82
+ // const fullPageData = await session.browser.screenshot(
83
+ // page,
84
+ // true, // fullPage
85
+ // {
86
+ // type: "jpeg",
87
+ // quality: 80
88
+ // }
89
+ // );
90
+ // console.log(`✅ Browser full page screenshot captured (${fullPageData.length} bytes)`);
91
+
92
+ // Save the full page screenshot
93
+ // await writeFile("browser_full_page_screenshot.jpg", Buffer.from(fullPageData));
94
+ // console.log("✅ Browser full page screenshot saved as browser_full_page_screenshot.jpg");
95
+
96
+ // Take a screenshot with custom viewport settings
97
+ // const customScreenshot = await session.browser.screenshot(
98
+ // page,
99
+ // false, // fullPage
100
+ // {
101
+ // type: "png",
102
+ // timeout: 30000
103
+ // }
104
+ // );
105
+ // console.log(`✅ Browser custom screenshot captured (${customScreenshot.length} bytes)`);
106
+
107
+ // Save the custom screenshot
108
+ // await writeFile("browser_custom_screenshot.png", Buffer.from(customScreenshot));
109
+ // console.log("✅ Browser custom screenshot saved as browser_custom_screenshot.png");
110
+
111
+ await browser.close();
112
+
113
+ console.log("ℹ️ Note: Screenshot functionality requires Playwright TypeScript integration");
114
+ console.log("✅ Browser screenshot demo completed");
115
+
116
+ } catch (error) {
117
+ console.error(`Error during screenshot demo: ${error}`);
118
+ } finally {
119
+ // Clean up: delete the session
120
+ console.log(`\n🧹 Cleaning up session ${session.sessionId}...`);
121
+ try {
122
+ await agentBay.delete(session);
123
+ console.log("✅ Session deleted successfully");
124
+ } catch (error) {
125
+ console.log(`⚠️ Warning: Error during cleanup: ${error}`);
126
+ }
127
+ }
128
+ }
129
+
130
+ console.log("📸 AgentBay Browser Screenshot Demo (TypeScript)");
131
+ console.log("=".repeat(50));
132
+ main().catch(console.error);
@@ -0,0 +1,252 @@
1
+ # Extension Management Example
2
+
3
+ This example demonstrates comprehensive browser extension management functionality using the Wuying AgentBay SDK for TypeScript.
4
+
5
+ ## Overview
6
+
7
+ The extension management system allows you to:
8
+ - Upload browser extensions (.zip files) to cloud storage
9
+ - List and manage existing extensions
10
+ - Create extension configurations for browser sessions
11
+ - Integrate extensions with browser automation workflows
12
+ - Handle multiple extensions in a single session
13
+ - Implement complete development workflows
14
+
15
+ ## File Structure
16
+
17
+ ```
18
+ extension-example/
19
+ ├── extension-example.ts # Comprehensive extension management examples
20
+ └── README.md # This documentation file
21
+ ```
22
+
23
+ ## Key Components
24
+
25
+ ### 1. Extension Class
26
+ Represents a browser extension with ID, name, and creation timestamp.
27
+
28
+ ```typescript
29
+ const extension = new Extension('ext_123', 'my-extension.zip', '2023-01-01');
30
+ ```
31
+
32
+ ### 2. ExtensionOption Class
33
+ Configuration for browser extension integration, encapsulating context ID and extension IDs.
34
+
35
+ ```typescript
36
+ const option = new ExtensionOption('context_123', ['ext_1', 'ext_2']);
37
+ ```
38
+
39
+ ### 3. ExtensionsService Class
40
+ Main service for managing extensions with automatic context handling.
41
+
42
+ ```typescript
43
+ const service = new ExtensionsService(agentBay, 'my_extensions');
44
+ ```
45
+
46
+ ## Examples Included
47
+
48
+ The `extension-example.ts` file contains comprehensive examples demonstrating:
49
+
50
+ ### 1. Basic Extension Management
51
+ - Upload a single extension
52
+ - Create extension options
53
+ - Integrate with browser sessions
54
+ - Basic error handling
55
+
56
+ ### 2. Multiple Extensions Handling
57
+ - Upload multiple extensions
58
+ - Create sessions with multiple extensions
59
+ - Batch operations
60
+
61
+ ### 3. Extension Development Workflow
62
+ - Complete development lifecycle
63
+ - Testing and validation patterns
64
+ - Extension updates
65
+ - Development context management
66
+
67
+ ### 4. Error Handling and Validation
68
+ - Proper validation patterns
69
+ - Common error scenarios
70
+ - Best practices for error management
71
+
72
+ ## Quick Start
73
+
74
+ ### Prerequisites
75
+
76
+ 1. **API Key**: Set your AgentBay API key
77
+ ```bash
78
+ export AGENTBAY_API_KEY="your-api-key-here"
79
+ ```
80
+
81
+ 2. **Extension Files**: Prepare your browser extension ZIP files
82
+ - Extensions must be in ZIP format
83
+ - Update file paths in the example code
84
+
85
+ ### Running the Example
86
+
87
+ ```bash
88
+ # Navigate to the TypeScript directory
89
+ cd typescript
90
+
91
+ # Install dependencies
92
+ npm install
93
+
94
+ # Build the project
95
+ npm run build
96
+
97
+ # Run the extension example
98
+ node docs/examples/extension-example/extension-example.js
99
+ ```
100
+
101
+ ### Code Example
102
+
103
+ ```typescript
104
+ import { AgentBay, ExtensionsService } from "wuying-agentbay-sdk";
105
+ import { CreateSessionParams, BrowserContext } from "wuying-agentbay-sdk";
106
+
107
+ // Initialize AgentBay client
108
+ const agentBay = new AgentBay({
109
+ apiKey: process.env.AGENTBAY_API_KEY,
110
+ });
111
+
112
+ // Create extensions service
113
+ const extensionsService = new ExtensionsService(agentBay, "browser_extensions");
114
+
115
+ try {
116
+ // Upload extension
117
+ const extension = await extensionsService.create("/path/to/extension.zip");
118
+
119
+ // Create extension option
120
+ const extOption = extensionsService.createExtensionOption([extension.id]);
121
+
122
+ // Create browser session with extension
123
+ const sessionParams = new CreateSessionParams()
124
+ .withLabels({ purpose: "extension_demo" })
125
+ .withBrowserContext(new BrowserContext(
126
+ "browser_session",
127
+ true,
128
+ extOption
129
+ ));
130
+
131
+ const sessionResult = await agentBay.create(sessionParams.toJSON());
132
+ const session = sessionResult.session;
133
+
134
+ console.log(`Session created with extension: ${session.sessionId}`);
135
+
136
+ } finally {
137
+ // Clean up resources
138
+ await extensionsService.cleanup();
139
+ }
140
+ ```
141
+
142
+ ## Extension Integration
143
+
144
+ ### Browser Context Integration
145
+
146
+ Extensions are automatically synchronized to `/tmp/extensions/` in browser sessions:
147
+
148
+ ```typescript
149
+ // Extension option contains all necessary configuration
150
+ const extOption = extensionsService.createExtensionOption(['ext_1', 'ext_2']);
151
+
152
+ // Use with BrowserContext
153
+ const browserContext = new BrowserContext(
154
+ "browser_session",
155
+ true, // auto-upload
156
+ extOption // extension configuration
157
+ );
158
+ ```
159
+
160
+ ### Context Management
161
+
162
+ The service supports two context modes:
163
+
164
+ 1. **Named Context**: Provide a specific context name
165
+ ```typescript
166
+ new ExtensionsService(agentBay, "my_extensions")
167
+ ```
168
+
169
+ 2. **Auto-Generated Context**: Let the service generate a context name
170
+ ```typescript
171
+ new ExtensionsService(agentBay) // Generates: extensions-{timestamp}
172
+ ```
173
+
174
+ ## API Reference
175
+
176
+ ### ExtensionsService Methods
177
+
178
+ - `create(localPath: string)` - Upload new extension
179
+ - `list()` - List all extensions in context
180
+ - `update(extensionId: string, newLocalPath: string)` - Update existing extension
181
+ - `delete(extensionId: string)` - Delete extension
182
+ - `createExtensionOption(extensionIds: string[])` - Create browser integration option
183
+ - `cleanup()` - Clean up auto-created contexts
184
+
185
+ ### ExtensionOption Methods
186
+
187
+ - `validate()` - Validate configuration
188
+ - `toString()` - String representation
189
+ - `toDisplayString()` - Human-readable description
190
+
191
+ ## Error Handling
192
+
193
+ The examples demonstrate comprehensive error handling:
194
+
195
+ ```typescript
196
+ try {
197
+ const extension = await extensionsService.create(extensionPath);
198
+ // Handle success
199
+ } catch (error) {
200
+ if (error.message.includes('File not found')) {
201
+ console.log('Extension file does not exist');
202
+ } else if (error.message.includes('Invalid format')) {
203
+ console.log('Extension must be a ZIP file');
204
+ } else {
205
+ console.log('Upload failed:', error.message);
206
+ }
207
+ }
208
+ ```
209
+
210
+ ## File Requirements
211
+
212
+ - **Format**: Extensions must be in ZIP format (.zip)
213
+ - **Structure**: Standard Chrome extension structure with manifest.json
214
+ - **Size**: Check AgentBay documentation for size limits
215
+ - **Permissions**: Ensure proper file permissions for reading
216
+
217
+ ## Common Use Cases
218
+
219
+ 1. **Extension Development**: Upload, test, and iterate on extensions
220
+ 2. **Automated Testing**: Test extensions in cloud browser environments
221
+ 3. **Batch Operations**: Manage multiple extensions simultaneously
222
+ 4. **CI/CD Integration**: Automate extension deployment workflows
223
+
224
+ ## Troubleshooting
225
+
226
+ ### Common Issues
227
+
228
+ 1. **File Not Found**: Ensure extension paths are correct
229
+ 2. **Invalid Format**: Only ZIP files are supported
230
+ 3. **API Key Missing**: Set AGENTBAY_API_KEY environment variable
231
+ 4. **Context Conflicts**: Use unique context names for different projects
232
+
233
+ ### Best Practices
234
+
235
+ 1. **Always cleanup**: Use try/finally blocks for resource cleanup
236
+ 2. **Validate inputs**: Check file existence before upload
237
+ 3. **Handle errors**: Implement proper error handling for all operations
238
+ 4. **Use descriptive names**: Name contexts and sessions clearly
239
+
240
+ ## Next Steps
241
+
242
+ - Explore the complete API documentation at `typescript/docs/api/browser-use/extension.md`
243
+ - Check browser automation examples for integration patterns
244
+ - Review the AgentBay SDK documentation for advanced features
245
+ - Consider implementing custom validation and testing workflows
246
+
247
+ ## Related Resources
248
+
249
+ - [Extension API Reference](../../../api/browser-use/extension.md) - Complete API documentation
250
+ - [Session API Reference](../../../api/common-features/basics/session.md) - Browser session management
251
+ - [Context API Reference](../../../api/common-features/basics/context.md) - Context management
252
+ - [AgentBay SDK Documentation](../../../api/common-features/basics/agentbay.md) - Core SDK features