You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: apps/site/docs/en/API.md
+32-10
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ And also, puppeteer agent has an extra option:
21
21
22
22
These are the main methods on all kinds of agents in Midscene.
23
23
24
-
> In the following documentation, you may see functions called with the `mid.` prefix. If you use destructuring in Playwright, like `async ({ ai, aiQuery }) => { /* ... */}`, you can call the functions without this prefix. It's just a matter of syntax.
24
+
> In the following documentation, you may see functions called with the `agent.` prefix. If you use destructuring in Playwright, like `async ({ ai, aiQuery }) => { /* ... */}`, you can call the functions without this prefix. It's just a matter of syntax.
25
25
26
26
### `.aiAction(steps: string)` or `.ai(steps: string)` - Interact with the page
27
27
@@ -32,11 +32,11 @@ You can use `.aiAction` to perform a series of actions. It accepts a `steps: str
32
32
These are some good samples:
33
33
34
34
```typescript
35
-
awaitmid.aiAction('Enter "Learn JS today" in the task box, then press Enter to create');
36
-
awaitmid.aiAction('Move your mouse over the second item in the task list and click the Delete button to the right of the second task');
35
+
awaitagent.aiAction('Enter "Learn JS today" in the task box, then press Enter to create');
36
+
awaitagent.aiAction('Move your mouse over the second item in the task list and click the Delete button to the right of the second task');
37
37
38
38
// use `.ai` shortcut
39
-
awaitmid.ai('Click the "completed" status button below the task list');
39
+
awaitagent.ai('Click the "completed" status button below the task list');
40
40
```
41
41
42
42
Steps should always be clearly and thoroughly described. A very brief prompt like 'Tweet "Hello World"' will result in unstable performance and a high likelihood of failure.
@@ -62,7 +62,7 @@ You can extract customized data from the UI. Provided that the multi-modal AI ca
62
62
For example, to parse detailed information from page:
63
63
64
64
```typescript
65
-
const dataA =awaitmid.aiQuery({
65
+
const dataA =awaitagent.aiQuery({
66
66
time: 'date and time, string',
67
67
userInfo: 'user info, {name: string}',
68
68
tableFields: 'field names of table, string[]',
@@ -74,18 +74,18 @@ You can also describe the expected return value format as a plain string:
74
74
75
75
```typescript
76
76
// dataB will be a string array
77
-
const dataB =awaitmid.aiQuery('string[], task names in the list');
77
+
const dataB =awaitagent.aiQuery('string[], task names in the list');
78
78
79
79
// dataC will be an array with objects
80
-
const dataC =awaitmid.aiQuery('{name: string, age: string}[], Data Record in the table');
80
+
const dataC =awaitagent.aiQuery('{name: string, age: string}[], Data Record in the table');
81
81
```
82
82
83
83
### `.aiAssert(assertion: string, errorMsg?: string)` - do an assertion
84
84
85
85
`.aiAssert` works just like the normal `assert` method, except that the condition is a prompt string written in natural language. Midscene will call AI to determine if the `assertion` is true. If the condition is not met, an error will be thrown containing `errorMsg` and a detailed reason generated by AI.
86
86
87
87
```typescript
88
-
awaitmid.aiAssert('The price of "Sauce Labs Onesie" is 7.99');
88
+
awaitagent.aiAssert('The price of "Sauce Labs Onesie" is 7.99');
89
89
```
90
90
91
91
:::tip
@@ -94,7 +94,7 @@ Assertions are usually a very important part of your script. To prevent the poss
94
94
For example, to replace the previous assertion,
95
95
96
96
```typescript
97
-
const items =awaitmid.aiQuery(
97
+
const items =awaitagent.aiQuery(
98
98
'"{name: string, price: number}[], return item name and price of each item',
When considering the time required for the AI service, `.aiWaitFor` may not be very efficient. Using a simple `sleep` method might be a useful alternative to `waitFor`.
111
111
112
112
```typescript
113
-
awaitmid.aiWaitFor("there is at least one headphone item on page");
113
+
awaitagent.aiWaitFor("there is at least one headphone item on page");
114
+
```
115
+
116
+
### `.runYaml(yamlScriptContent: string)` - run a yaml script
117
+
118
+
`.runYaml` will run the `tasks` part of the yaml script and return the result of all the `.aiQuery` calls (if any). The `target` part of the yaml script will be ignored in this function.
119
+
120
+
To ignore some errors while running, you can set the `continueOnError` option in the yaml script. For more details about the yaml script schema, please refer to [Automate with Scripts in YAML](./automate-with-scripts-in-yaml).
Copy file name to clipboardexpand all lines: apps/site/docs/en/automate-with-scripts-in-yaml.mdx
+22
Original file line number
Diff line number
Diff line change
@@ -206,10 +206,32 @@ You can use the environment variable in the `.yaml` file like this:
206
206
```
207
207
208
208
## Use bridge mode
209
+
209
210
By using bridge mode, you can utilize YAML scripts to automate the web browser on your desktop. This is particularly useful if you want to reuse cookies, plugins, and page states, or if you want to manually interact with automation scripts.
210
211
211
212
See [Bridge Mode by Chrome Extension](./bridge-mode-by-chrome-extension) for more details.
212
213
214
+
## Run yaml script with javascript
215
+
216
+
You can also run a yaml script with javascript by using the `runYaml` method of the Midscene agent. Only the `tasks` part of the yaml script will be executed.
0 commit comments