-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathdemo-new-tab.ts
More file actions
25 lines (21 loc) · 984 Bytes
/
demo-new-tab.ts
File metadata and controls
25 lines (21 loc) · 984 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import 'dotenv/config'; // read environment variables from .env file
import { AgentOverChromeBridge } from '@midscene/web/bridge-mode';
const sleep = (ms: number | undefined) => new Promise((r) => setTimeout(r, ms));
Promise.resolve(
(async () => {
const agent = new AgentOverChromeBridge({
// uncomment this to close the new tab when destroying the agent
// closeNewTabsAfterDisconnect: true,
});
// This will connect to a new tab on your desktop Chrome
// remember to start your chrome extension, click 'allow connection' button.
await agent.connectNewTabWithUrl('https://www.bing.com');
// After connected, you can see this log. Otherwise you will get an timeout error.
console.log('connected to a new tab !');
// these are the same as normal Midscene agent
await agent.aiAct('type "AI 101" and hit Enter');
await sleep(3000);
await agent.aiAssert('there are some search results');
await agent.destroy();
})()
);