-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add demo for bridge mode (#27)
* fix: update fixture of playwright demo * feat: add demo for bridge mode * feat: add demo for bridge mode * feat: add 'current tab' demo * feat: add sample code file * chore: use latest version in bridge moe
- Loading branch information
1 parent
3600fa7
commit 2906d3b
Showing
13 changed files
with
161 additions
and
436 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package-lock.json | ||
.env | ||
|
||
# Midscene.js dump files | ||
midscene_run/midscene-report | ||
midscene_run/dump-logger | ||
|
||
midscene_run/cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Bridge mode demo | ||
|
||
This is a demo to show how to use bridge mode to control the page on your desktop Chrome. | ||
|
||
## Steps | ||
|
||
Install Midscene extension from chrome web store: [Midscene](https://chromewebstore.google.com/detail/midscene/gbldofcpkknbggpkmbdaefngejllnief) | ||
|
||
create `.env` file | ||
|
||
```shell | ||
# replace by your own | ||
OPENAI_API_KEY="YOUR_TOKEN" | ||
``` | ||
|
||
install deps | ||
|
||
```bash | ||
npm install | ||
``` | ||
|
||
Run demo to create new tabs. | ||
Remember to click the "Allow connection" button from Chrome extension while running. | ||
|
||
```bash | ||
npm run demo | ||
``` | ||
|
||
Run demo to connect to the active tab. | ||
|
||
```bash | ||
npm run demo-current-tab | ||
``` | ||
|
||
# Reference | ||
|
||
https://midscenejs.com/bridge-mode-by-chrome-extension | ||
https://midscenejs.com/api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { AgentOverChromeBridge } from "@midscene/web/bridge-mode"; | ||
import "dotenv/config"; | ||
|
||
Promise.resolve( | ||
(async () => { | ||
const agent = new AgentOverChromeBridge(); | ||
|
||
// This will connect to **the current active tab** on your desktop Chrome | ||
// remember to start your chrome extension, click 'allow connection' button. | ||
await agent.connectCurrentTab(); | ||
// After connected, you can see this log. Otherwise you will get an timeout error. | ||
console.log("connected to the active tab !"); | ||
|
||
const content = await agent.aiQuery( | ||
"what is the title of the page? answer in {title: string}" | ||
); | ||
console.log(content); | ||
await agent.destroy(); | ||
})() | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { AgentOverChromeBridge } from "@midscene/web/bridge-mode"; | ||
import "dotenv/config"; | ||
|
||
const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); | ||
Promise.resolve( | ||
(async () => { | ||
const agent = new AgentOverChromeBridge(); | ||
|
||
// 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.aiAction('type "AI 101" and hit Enter'); | ||
await sleep(3000); | ||
|
||
await agent.aiAssert("there are some search results"); | ||
await agent.destroy(); | ||
})() | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "bridge-mode-demo", | ||
"private": true, | ||
"version": "1.0.0", | ||
"description": "> quick start", | ||
"main": "index.js", | ||
"type": "module", | ||
"scripts": { | ||
"demo": "npx tsx demo-new-tab.ts", | ||
"demo-current-tab": "npx tsx demo-current-tab.ts" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"@midscene/web": "latest", | ||
"dotenv": "^16.4.5", | ||
"tsx": "^4.19.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { test as base } from '@playwright/test'; | ||
import type { PlayWrightAiFixtureType } from '@midscene/web'; | ||
import { PlaywrightAiFixture } from '@midscene/web'; | ||
import { test as base } from "@playwright/test"; | ||
import type { PlayWrightAiFixtureType } from "@midscene/web/playwright"; | ||
import { PlaywrightAiFixture } from "@midscene/web/playwright"; | ||
|
||
export const test = base.extend<PlayWrightAiFixtureType>(PlaywrightAiFixture()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.