Skip to content

Commit a114e70

Browse files
yuyutaotaozhoushaw
andauthored
feat: show pointer position in chrome extension (#286)
--------- Co-authored-by: zhouxiao.shaw <[email protected]>
1 parent 918e6a3 commit a114e70

File tree

17 files changed

+338
-138
lines changed

17 files changed

+338
-138
lines changed

apps/site/docs/en/model-provider.md

+2
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ There are some extra configs when using Azure OpenAI Service.
8686

8787
### Use ADT token provider
8888

89+
This mode cannot be used in Chrome extension.
90+
8991
```bash
9092
# this is always true when using Azure OpenAI Service
9193
export MIDSCENE_USE_AZURE_OPENAI=1

apps/site/docs/en/quick-experience.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ It's mainly due to conflicts with other extensions injecting `<iframe />` or `<s
4949
To find the suspicious plugins:
5050

5151
1. Open the Devtools of the page, find the `<script>` or `<iframe>` with a url like `chrome-extension://{ID-of-the-suspicious-plugin}/...`.
52-
2. Copy the ID from the url, open chrome://extensions/, find the plugin with the same ID, disable it.
52+
2. Copy the ID from the url, open `chrome://extensions/` , use cmd+f to find the plugin with the same ID, disable it.
5353
3. Refresh the page, try again.

apps/site/docs/zh/model-provider.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ import 'dotenv/config';
7373

7474
## 使用 Azure OpenAI 服务时的配置
7575

76-
使用 ADT token provider
76+
### 使用 ADT token provider
77+
78+
此种模式无法运行在浏览器插件中。
7779

7880
```bash
7981
# 使用 Azure OpenAI 服务时,配置为 1
@@ -85,7 +87,7 @@ export AZURE_OPENAI_API_VERSION="2024-05-01-preview"
8587
export AZURE_OPENAI_DEPLOYMENT="gpt-4o"
8688
```
8789

88-
使用 keyless 模式
90+
### 使用 keyless 模式
8991

9092
```bash
9193
export MIDSCENE_USE_AZURE_OPENAI=1

apps/site/docs/zh/quick-experience.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,5 @@ OPENAI_API_KEY="sk-replace-by-your-own"
4747
找到可疑插件:
4848

4949
1. 打开页面的调试器,找到被其他插件注入的 `<iframe />``<script />`,一般 URL 是 `chrome-extension://{这串就是ID}/...` 格式,复制其 ID。
50-
2. 打开 chrome://extensions/找到相同 ID 的插件,禁用它。
50+
2. 打开 `chrome://extensions/` ,用 cmd+f 找到相同 ID 的插件,禁用它。
5151
3. 刷新页面,再次尝试。

packages/midscene/src/ai-model/prompt/llm-planning.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,16 @@ The JSON format is as follows:
122122
{{
123123
"actions": [
124124
{{
125-
"thought": "Reasons for generating this task, and why this task is feasible on this page",
125+
"thought": "Reasons for generating this task, and why this task is feasible on this page.", // Use the same language as the user's instruction.
126126
"type": "Tap",
127127
"param": null,
128128
"locate": {sample} | null,
129129
}},
130130
// ... more actions
131131
],
132132
"taskWillBeAccomplished": boolean,
133-
"furtherPlan": {{ "whatHaveDone": string, "whatToDoNext": string }} | null,
134-
"error"?: string
133+
"furtherPlan": {{ "whatHaveDone": string, "whatToDoNext": string }} | null, // Use the same language as the user's instruction.
134+
"error"?: string // Use the same language as the user's instruction.
135135
}}
136136
Here is an example of how to decompose a task:
137137

packages/midscene/src/insight/utils.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import assert from 'node:assert';
2-
import { randomUUID } from 'node:crypto';
32
/* eslint-disable @typescript-eslint/ban-types */
43
import { existsSync } from 'node:fs';
54
import { join } from 'node:path';
6-
import { MIDSCENE_MODEL_NAME, getAIConfig } from '@/env';
5+
import {
6+
MIDSCENE_MODEL_NAME,
7+
MIDSCENE_USE_VLM_UI_TARS,
8+
getAIConfig,
9+
} from '@/env';
710
import type {
8-
BaseElement,
911
DumpMeta,
1012
DumpSubscriber,
11-
ElementById,
1213
InsightDump,
1314
PartialInsightDumpFromSDK,
1415
} from '@/types';
@@ -40,6 +41,9 @@ export function writeInsightDump(
4041
sdkVersion: getVersion(),
4142
logTime: Date.now(),
4243
model_name: getAIConfig(MIDSCENE_MODEL_NAME) || '',
44+
model_description: getAIConfig(MIDSCENE_USE_VLM_UI_TARS)
45+
? 'vlm-ui-tars enabled'
46+
: '',
4347
};
4448
const finalData: InsightDump = {
4549
logId: id,

packages/midscene/src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export interface DumpMeta {
140140
sdkVersion: string;
141141
logTime: number;
142142
model_name: string;
143+
model_description?: string;
143144
}
144145

145146
export interface ReportDumpWithAttributes {

packages/visualizer/src/component/logo.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import './logo.less';
22

3+
export const LogoUrl =
4+
'https://lf3-static.bytednsdoc.com/obj/eden-cn/vhaeh7vhabf/Midscene.png';
5+
36
const Logo = ({ withGithubStar = false }: { withGithubStar?: boolean }) => {
47
if (withGithubStar) {
58
return (
69
<div className="logo logo-with-star-wrapper">
7-
<img
8-
alt="Midscene_logo"
9-
src="https://lf3-static.bytednsdoc.com/obj/eden-cn/vhaeh7vhabf/Midscene.png"
10-
/>
10+
<img alt="Midscene_logo" src={LogoUrl} />
1111
<a
1212
href="https://github.com/web-infra-dev/midscene"
1313
target="_blank"

packages/visualizer/src/component/playground-component.tsx

+9-10
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import type { WebUIContext } from '@midscene/web/utils';
3333
import type { MenuProps } from 'antd';
3434
import { Dropdown, Space } from 'antd';
3535
import { EnvConfig } from './env-config';
36-
import { type HistoryItem, useChromeTabInfo, useEnvConfig } from './store';
36+
import { type HistoryItem, useEnvConfig } from './store';
3737

3838
import {
3939
ChromeExtensionProxyPage,
@@ -339,16 +339,15 @@ export function Playground({
339339
}
340340
}
341341
} catch (e: any) {
342+
const errorMessage = e?.message || '';
342343
console.error(e);
343-
if (typeof e === 'string') {
344-
if (e.includes('of different extension')) {
345-
result.error =
346-
'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://midscenejs.com/quick-experience.html#faq';
347-
} else {
348-
result.error = e;
349-
}
350-
} else if (!e.message?.includes(ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED)) {
351-
result.error = e.message;
344+
if (errorMessage.includes('of different extension')) {
345+
result.error =
346+
'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://midscenejs.com/quick-experience.html#faq';
347+
} else if (
348+
!errorMessage?.includes(ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED)
349+
) {
350+
result.error = errorMessage;
352351
} else {
353352
result.error = 'Unknown error';
354353
}

packages/visualizer/src/component/replay-scripts.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ export interface ReplayScriptsInfo {
119119
height: number;
120120
sdkVersion?: string;
121121
modelName?: string;
122+
modelDescription?: string;
122123
}
123124

124125
export const allScriptsFromDump = (
@@ -129,6 +130,7 @@ export const allScriptsFromDump = (
129130
let height = 0;
130131
let sdkVersion = '';
131132
let modelName = '';
133+
let modelDescription = '';
132134

133135
dump.executions.forEach((execution) => {
134136
execution.tasks.forEach((task) => {
@@ -145,6 +147,10 @@ export const allScriptsFromDump = (
145147
if (insightTask.log?.dump?.model_name) {
146148
modelName = insightTask.log.dump.model_name;
147149
}
150+
151+
if (insightTask.log?.dump?.model_description) {
152+
modelDescription = insightTask.log.dump.model_description;
153+
}
148154
});
149155
});
150156

@@ -176,6 +182,7 @@ export const allScriptsFromDump = (
176182
height,
177183
sdkVersion,
178184
modelName,
185+
modelDescription,
179186
};
180187
};
181188

packages/visualizer/src/component/sidebar.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const SideItem = (props: {
6363
const Sidebar = (): JSX.Element => {
6464
const sdkVersion = useExecutionDump((store) => store.sdkVersion);
6565
const modelName = useExecutionDump((store) => store.modelName);
66+
const modelDescription = useExecutionDump((store) => store.modelDescription);
6667
const groupedDump = useExecutionDump((store) => store.dump);
6768
const setActiveTask = useExecutionDump((store) => store.setActiveTask);
6869
const activeTask = useExecutionDump((store) => store.activeTask);
@@ -110,8 +111,9 @@ const Sidebar = (): JSX.Element => {
110111
};
111112
}, [currentSelectedIndex, allTasks, setActiveTask]);
112113

114+
const modelDescriptionText = modelDescription ? `, ${modelDescription}` : '';
113115
const envInfo = sdkVersion
114-
? `v${sdkVersion}, ${modelName || 'default model'}`
116+
? `v${sdkVersion}, ${modelName || 'default model'}${modelDescriptionText}`
115117
: '';
116118

117119
const sideList = groupedDump ? (

packages/visualizer/src/component/store.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ export const useChromeTabInfo = create<{
9191
};
9292

9393
Promise.resolve().then(async () => {
94+
if (typeof window.chrome === 'undefined') {
95+
return;
96+
}
9497
const tab = await activeTab();
9598
const windowId = await currentWindowId();
9699
set({
@@ -206,6 +209,7 @@ export const useExecutionDump = create<{
206209
allExecutionAnimation: AnimationScript[] | null;
207210
sdkVersion: string | null;
208211
modelName: string | null;
212+
modelDescription: string | null;
209213
insightWidth: number | null;
210214
insightHeight: number | null;
211215
activeExecution: ExecutionDump | null;
@@ -228,6 +232,7 @@ export const useExecutionDump = create<{
228232
allExecutionAnimation: null,
229233
sdkVersion: null,
230234
modelName: null,
235+
modelDescription: null,
231236
insightWidth: null,
232237
insightHeight: null,
233238
activeTask: null,
@@ -297,6 +302,7 @@ export const useExecutionDump = create<{
297302
width,
298303
height,
299304
modelName,
305+
modelDescription,
300306
sdkVersion,
301307
} = allScriptsInfo;
302308

@@ -307,6 +313,7 @@ export const useExecutionDump = create<{
307313
insightWidth: width,
308314
insightHeight: height,
309315
modelName,
316+
modelDescription,
310317
sdkVersion,
311318
});
312319
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const styleElements = document.querySelectorAll('[id="water-flow-animation"]');
2-
styleElements.forEach((element) => {
3-
document.head.removeChild(element);
4-
});
1+
if (typeof window.midsceneWaterFlowAnimation !== 'undefined') {
2+
window.midsceneWaterFlowAnimation.disable();
3+
}

0 commit comments

Comments
 (0)