Skip to content

Commit a3f7b33

Browse files
committed
Merge branch 'main' into feat/android-screenshot-resize-ratio
2 parents 07ab27e + f99c220 commit a3f7b33

File tree

42 files changed

+9031
-182
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+9031
-182
lines changed

apps/chrome-extension/static/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "Midscene.js",
33
"description": "Open-source SDK for automating web pages using natural language through AI.",
4-
"version": "0.130",
4+
"version": "0.132",
55
"manifest_version": 3,
66
"permissions": [
77
"activeTab",

apps/site/docs/en/caching.mdx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,33 @@ agent:
5151
5252
### Read-write mode
5353
54-
Configuration: `cache: { id: "my-cache-id" }`
54+
Configuration: `cache: { id: "my-cache-id" }` or `cache: { strategy: "read-write", id: "my-cache-id" }`
5555

56-
Automatically read existing cache and update cache files during execution.
56+
Automatically read existing cache and update cache files during execution. The default value of `strategy` is `read-write`.
5757

5858
```javascript
5959
// Direct Agent creation - explicit cache ID
6060
const agent = new PuppeteerAgent(page, {
6161
cache: { id: "my-cache-id" },
6262
});
63+
64+
// Explicitly specify strategy
65+
const agent = new PuppeteerAgent(page, {
66+
cache: { strategy: "read-write", id: "my-cache-id" },
67+
});
6368
```
6469

6570
```yaml
6671
# YAML configuration - explicit cache ID
6772
agent:
6873
cache:
6974
id: "my-cache-test"
75+
76+
# Explicitly specify strategy
77+
agent:
78+
cache:
79+
id: "my-cache-test"
80+
strategy: "read-write"
7081
```
7182

7283
YAML mode also supports `cache: true` to automatically use the file name as the cache ID.

apps/site/docs/en/integrate-with-android.mdx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,40 @@ await agent.launch('com.android.settings'); // open a native page
164164
await agent.launch('com.android.settings/.Settings'); // open a native page
165165
```
166166

167+
#### `agent.runAdbShell()`
168+
169+
Execute a command through `adb shell` on the connected device.
170+
171+
> Note: This method wraps `adb shell` and forwards the command directly to the device.
172+
173+
- Type
174+
175+
```typescript
176+
function runAdbShell(command: string): Promise<string>;
177+
```
178+
179+
- Parameters:
180+
181+
- `command: string` - The adb shell command to execute.
182+
183+
- Return Value:
184+
185+
- `Promise<string>` - Returns a Promise that resolves to the command output.
186+
187+
- Examples:
188+
189+
```typescript
190+
import { AndroidAgent, AndroidDevice } from '@midscene/android';
191+
192+
const device = new AndroidDevice('s4ey59');
193+
const agent = new AndroidAgent(device);
194+
await device.connect();
195+
196+
const result = await agent.runAdbShell('dumpsys battery');
197+
// Equivalent to running `adb shell dumpsys battery`
198+
console.log(result);
199+
```
200+
167201
#### `agentFromAdbDevice()`
168202

169203
Create a AndroidAgent from a connected adb device.

apps/site/docs/zh/caching.mdx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,22 +54,33 @@ agent:
5454
5555
### 读写模式
5656
57-
配置方式:`cache: { id: "my-cache-id" }`
57+
配置方式:`cache: { id: "my-cache-id" }` 或 `cache: { strategy: "read-write", id: "my-cache-id" }`
5858

59-
自动读取已有缓存,执行过程中自动更新缓存文件。
59+
自动读取已有缓存,执行过程中自动更新缓存文件。`strategy` 的默认值是 `read-write`。
6060

6161
```javascript
6262
// 直接创建 Agent - 显式设置 cache ID
6363
const agent = new PuppeteerAgent(page, {
6464
cache: { id: "my-cache-id" },
6565
});
66+
67+
// 显式指定 strategy
68+
const agent = new PuppeteerAgent(page, {
69+
cache: { strategy: "read-write", id: "my-cache-id" },
70+
});
6671
```
6772

6873
```yaml
6974
# YAML 配置 - 显式设置 cache ID
7075
agent:
7176
cache:
7277
id: "my-cache-test"
78+
79+
# 显式指定 strategy
80+
agent:
81+
cache:
82+
id: "my-cache-test"
83+
strategy: "read-write"
7384
```
7485

7586
YAML 模式还支持配置 `cache: true`,自动使用文件名作为 cache ID。

apps/site/docs/zh/integrate-with-android.mdx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,40 @@ await agent.launch('com.android.settings'); // 打开系统设置 app(package na
163163
await agent.launch('com.android.settings/.Settings'); // 打开系统设置 app(package name) 的 .Settings(activity name) 页面
164164
```
165165

166+
#### `agent.runAdbShell()`
167+
168+
执行 `adb shell` 命令。
169+
170+
> 注意:该方法本质上是调用 `adb shell` 执行传入的命令。
171+
172+
- 类型
173+
174+
```typescript
175+
function runAdbShell(command: string): Promise<string>;
176+
```
177+
178+
- 参数:
179+
180+
- `command: string` - 要执行的 adb shell 命令
181+
182+
- 返回值:
183+
184+
- `Promise<string>` - 命令执行的输出结果
185+
186+
- 示例:
187+
188+
```typescript
189+
import { AndroidAgent, AndroidDevice } from '@midscene/android';
190+
191+
const page = new AndroidDevice('s4ey59');
192+
const agent = new AndroidAgent(page);
193+
await page.connect();
194+
195+
const result = await agent.runAdbShell('dumpsys battery');
196+
// 等同于执行 `adb shell dumpsys battery`
197+
console.log(result);
198+
```
199+
166200
#### `agentFromAdbDevice()`
167201

168202
从已连接的 adb 设备中,创建一个 AndroidAgent。

0 commit comments

Comments
 (0)