Skip to content

Commit 2a05c1a

Browse files
authored
chore: update examples (#82)
1 parent ccf93ca commit 2a05c1a

File tree

6 files changed

+13
-23
lines changed

6 files changed

+13
-23
lines changed

puppeteer-demo/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ Refer to this document if your want to use other models like Qwen: https://midsc
2323
### Run demo
2424

2525
```bash
26-
npm install
27-
26+
npm install
27+
# Puppeteer needs download a compatible Chrome
28+
npx puppeteer browsers install chrome
2829
# run demo.ts
2930
npx tsx demo.ts
3031

puppeteer-demo/demo-run-yaml.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ Promise.resolve(
1515
await page.setViewport({
1616
width: 1280,
1717
height: 800,
18-
deviceScaleFactor: os.platform() === 'darwin' ? 2 : 1, // this is used to avoid flashing on UI Mode when doing screenshot on Mac
18+
deviceScaleFactor: 0
1919
});
2020

21-
await page.goto('https://www.bing.com/shop/');
21+
await page.goto('https://www.bing.com/');
2222
await sleep(5000);
2323

2424
const agent = new PuppeteerAgent(page);
@@ -28,7 +28,7 @@ Promise.resolve(
2828
tasks:
2929
- name: search
3030
flow:
31-
- ai: input 'Headphones' in search box, click search button
31+
- ai: input 'Headphones Price' in search box, click search button
3232
- sleep: 3000
3333
3434
- name: query
@@ -38,7 +38,6 @@ tasks:
3838
- aiNumber: "What is the price of the first headphone?"
3939
- aiBoolean: "Is the price of the first headphone more than 1000?"
4040
- aiString: "What is the name of the first headphone?"
41-
- aiLocate: "What is the location of the first headphone?"
4241
`);
4342

4443
console.log(result);

puppeteer-demo/demo.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11
import puppeteer from 'puppeteer';
2-
import os from 'node:os';
32
import { PuppeteerAgent } from '@midscene/web/puppeteer';
43
import 'dotenv/config'; // read environment variables from .env file
54

65
const sleep = (ms: number | undefined) => new Promise((r) => setTimeout(r, ms));
76
Promise.resolve(
87
(async () => {
98
const browser = await puppeteer.launch({
10-
headless: true, // 'true' means we can't see the browser window
9+
headless: false, // 'false' means we can see the browser window
1110
args: ['--no-sandbox', '--disable-setuid-sandbox'],
1211
});
1312

1413
const page = await browser.newPage();
1514
await page.setViewport({
1615
width: 1280,
1716
height: 768,
18-
deviceScaleFactor: os.platform() === 'darwin' ? 2 : 1, // this is used to avoid flashing on UI Mode when doing screenshot on Mac
17+
deviceScaleFactor: 0
1918
});
2019

21-
await page.goto('https://www.bing.com/shop');
20+
await page.goto('https://www.bing.com');
2221
await sleep(5000);
2322

2423
// 👀 init Midscene agent
2524
const agent = new PuppeteerAgent(page);
2625

2726
// 👀 type keywords, perform a search
28-
await agent.aiAct('type "Headphones" in search box, hit Enter');
27+
await agent.aiAct('type "Headphones Price" in search box, hit Enter');
2928

3029
// 👀 wait for the loading
3130
await agent.aiWaitFor('there is at least one headphone item on page');
@@ -55,14 +54,6 @@ Promise.resolve(
5554
);
5655
console.log('name', name);
5756

58-
const location = await agent.aiLocate(
59-
'What is the location of the first headphone?'
60-
);
61-
console.log('location', location);
62-
63-
// 👀 assert by AI
64-
await agent.aiAssert('There is a category filter on the left');
65-
6657
// 👀 click on the first item
6758
await agent.aiTap('the first item in the list');
6859

puppeteer-demo/extract-data.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import puppeteer from 'puppeteer';
2-
import os from 'node:os';
32
import { PuppeteerAgent } from '@midscene/web/puppeteer';
43
import 'dotenv/config'; // read environment variables from .env file
54

@@ -16,7 +15,7 @@ Promise.resolve(
1615
await page.setViewport({
1716
width: 1280,
1817
height: 768,
19-
deviceScaleFactor: os.platform() === 'darwin' ? 2 : 1,
18+
deviceScaleFactor: 0,
2019
});
2120

2221
// Load the contacts demo page (replace with your actual file path or URL)

remote-puppeteer-demo/demo.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import puppeteer from 'puppeteer';
2-
import os from 'node:os';
32
import { PuppeteerAgent } from '@midscene/web/puppeteer';
43
import 'dotenv/config'; // read environment variables from .env file
54

@@ -38,7 +37,7 @@ Promise.resolve(
3837
await page.setViewport({
3938
width: 1280,
4039
height: 768,
41-
deviceScaleFactor: os.platform() === 'darwin' ? 2 : 1,
40+
deviceScaleFactor: 0,
4241
});
4342

4443
console.log('🌐 Navigating to Bing Shopping...');

yaml-scripts-demo/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ MIDSCENE_MODEL_BASE_URL="https://.../compatible-mode/v1"
1111
MIDSCENE_MODEL_API_KEY="sk-abcdefghijklmnopqrstuvwxyz"
1212
MIDSCENE_MODEL_NAME="qwen3-vl-plus"
1313
MIDSCENE_MODEL_FAMILY="qwen3-vl"
14+
```
1415

1516
Refer to this document if your want to use other models like Qwen: https://midscenejs.com/model-strategy.html
1617

0 commit comments

Comments
 (0)