Skip to content

Commit

Permalink
feat: show pointer position in chrome extension (#286)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: zhouxiao.shaw <[email protected]>
  • Loading branch information
yuyutaotao and zhoushaw authored Jan 17, 2025
1 parent 918e6a3 commit a114e70
Show file tree
Hide file tree
Showing 17 changed files with 338 additions and 138 deletions.
2 changes: 2 additions & 0 deletions apps/site/docs/en/model-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ There are some extra configs when using Azure OpenAI Service.

### Use ADT token provider

This mode cannot be used in Chrome extension.

```bash
# this is always true when using Azure OpenAI Service
export MIDSCENE_USE_AZURE_OPENAI=1
Expand Down
2 changes: 1 addition & 1 deletion apps/site/docs/en/quick-experience.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ It's mainly due to conflicts with other extensions injecting `<iframe />` or `<s
To find the suspicious plugins:

1. Open the Devtools of the page, find the `<script>` or `<iframe>` with a url like `chrome-extension://{ID-of-the-suspicious-plugin}/...`.
2. Copy the ID from the url, open chrome://extensions/, find the plugin with the same ID, disable it.
2. Copy the ID from the url, open `chrome://extensions/` , use cmd+f to find the plugin with the same ID, disable it.
3. Refresh the page, try again.
6 changes: 4 additions & 2 deletions apps/site/docs/zh/model-provider.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ import 'dotenv/config';

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

使用 ADT token provider
### 使用 ADT token provider

此种模式无法运行在浏览器插件中。

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

使用 keyless 模式
### 使用 keyless 模式

```bash
export MIDSCENE_USE_AZURE_OPENAI=1
Expand Down
2 changes: 1 addition & 1 deletion apps/site/docs/zh/quick-experience.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,5 @@ OPENAI_API_KEY="sk-replace-by-your-own"
找到可疑插件:

1. 打开页面的调试器,找到被其他插件注入的 `<iframe />``<script />`,一般 URL 是 `chrome-extension://{这串就是ID}/...` 格式,复制其 ID。
2. 打开 chrome://extensions/找到相同 ID 的插件,禁用它。
2. 打开 `chrome://extensions/` ,用 cmd+f 找到相同 ID 的插件,禁用它。
3. 刷新页面,再次尝试。
6 changes: 3 additions & 3 deletions packages/midscene/src/ai-model/prompt/llm-planning.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ The JSON format is as follows:
{{
"actions": [
{{
"thought": "Reasons for generating this task, and why this task is feasible on this page",
"thought": "Reasons for generating this task, and why this task is feasible on this page.", // Use the same language as the user's instruction.
"type": "Tap",
"param": null,
"locate": {sample} | null,
}},
// ... more actions
],
"taskWillBeAccomplished": boolean,
"furtherPlan": {{ "whatHaveDone": string, "whatToDoNext": string }} | null,
"error"?: string
"furtherPlan": {{ "whatHaveDone": string, "whatToDoNext": string }} | null, // Use the same language as the user's instruction.
"error"?: string // Use the same language as the user's instruction.
}}
Here is an example of how to decompose a task:
Expand Down
12 changes: 8 additions & 4 deletions packages/midscene/src/insight/utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import assert from 'node:assert';
import { randomUUID } from 'node:crypto';
/* eslint-disable @typescript-eslint/ban-types */
import { existsSync } from 'node:fs';
import { join } from 'node:path';
import { MIDSCENE_MODEL_NAME, getAIConfig } from '@/env';
import {
MIDSCENE_MODEL_NAME,
MIDSCENE_USE_VLM_UI_TARS,
getAIConfig,
} from '@/env';
import type {
BaseElement,
DumpMeta,
DumpSubscriber,
ElementById,
InsightDump,
PartialInsightDumpFromSDK,
} from '@/types';
Expand Down Expand Up @@ -40,6 +41,9 @@ export function writeInsightDump(
sdkVersion: getVersion(),
logTime: Date.now(),
model_name: getAIConfig(MIDSCENE_MODEL_NAME) || '',
model_description: getAIConfig(MIDSCENE_USE_VLM_UI_TARS)
? 'vlm-ui-tars enabled'
: '',
};
const finalData: InsightDump = {
logId: id,
Expand Down
1 change: 1 addition & 0 deletions packages/midscene/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export interface DumpMeta {
sdkVersion: string;
logTime: number;
model_name: string;
model_description?: string;
}

export interface ReportDumpWithAttributes {
Expand Down
8 changes: 4 additions & 4 deletions packages/visualizer/src/component/logo.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import './logo.less';

export const LogoUrl =
'https://lf3-static.bytednsdoc.com/obj/eden-cn/vhaeh7vhabf/Midscene.png';

const Logo = ({ withGithubStar = false }: { withGithubStar?: boolean }) => {
if (withGithubStar) {
return (
<div className="logo logo-with-star-wrapper">
<img
alt="Midscene_logo"
src="https://lf3-static.bytednsdoc.com/obj/eden-cn/vhaeh7vhabf/Midscene.png"
/>
<img alt="Midscene_logo" src={LogoUrl} />
<a
href="https://github.com/web-infra-dev/midscene"
target="_blank"
Expand Down
19 changes: 9 additions & 10 deletions packages/visualizer/src/component/playground-component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import type { WebUIContext } from '@midscene/web/utils';
import type { MenuProps } from 'antd';
import { Dropdown, Space } from 'antd';
import { EnvConfig } from './env-config';
import { type HistoryItem, useChromeTabInfo, useEnvConfig } from './store';
import { type HistoryItem, useEnvConfig } from './store';

import {
ChromeExtensionProxyPage,
Expand Down Expand Up @@ -339,16 +339,15 @@ export function Playground({
}
}
} catch (e: any) {
const errorMessage = e?.message || '';
console.error(e);
if (typeof e === 'string') {
if (e.includes('of different extension')) {
result.error =
'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://midscenejs.com/quick-experience.html#faq';
} else {
result.error = e;
}
} else if (!e.message?.includes(ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED)) {
result.error = e.message;
if (errorMessage.includes('of different extension')) {
result.error =
'Conflicting extension detected. Please disable the suspicious plugins and refresh the page. Guide: https://midscenejs.com/quick-experience.html#faq';
} else if (
!errorMessage?.includes(ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED)
) {
result.error = errorMessage;
} else {
result.error = 'Unknown error';
}
Expand Down
7 changes: 7 additions & 0 deletions packages/visualizer/src/component/replay-scripts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ export interface ReplayScriptsInfo {
height: number;
sdkVersion?: string;
modelName?: string;
modelDescription?: string;
}

export const allScriptsFromDump = (
Expand All @@ -129,6 +130,7 @@ export const allScriptsFromDump = (
let height = 0;
let sdkVersion = '';
let modelName = '';
let modelDescription = '';

dump.executions.forEach((execution) => {
execution.tasks.forEach((task) => {
Expand All @@ -145,6 +147,10 @@ export const allScriptsFromDump = (
if (insightTask.log?.dump?.model_name) {
modelName = insightTask.log.dump.model_name;
}

if (insightTask.log?.dump?.model_description) {
modelDescription = insightTask.log.dump.model_description;
}
});
});

Expand Down Expand Up @@ -176,6 +182,7 @@ export const allScriptsFromDump = (
height,
sdkVersion,
modelName,
modelDescription,
};
};

Expand Down
4 changes: 3 additions & 1 deletion packages/visualizer/src/component/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const SideItem = (props: {
const Sidebar = (): JSX.Element => {
const sdkVersion = useExecutionDump((store) => store.sdkVersion);
const modelName = useExecutionDump((store) => store.modelName);
const modelDescription = useExecutionDump((store) => store.modelDescription);
const groupedDump = useExecutionDump((store) => store.dump);
const setActiveTask = useExecutionDump((store) => store.setActiveTask);
const activeTask = useExecutionDump((store) => store.activeTask);
Expand Down Expand Up @@ -110,8 +111,9 @@ const Sidebar = (): JSX.Element => {
};
}, [currentSelectedIndex, allTasks, setActiveTask]);

const modelDescriptionText = modelDescription ? `, ${modelDescription}` : '';
const envInfo = sdkVersion
? `v${sdkVersion}, ${modelName || 'default model'}`
? `v${sdkVersion}, ${modelName || 'default model'}${modelDescriptionText}`
: '';

const sideList = groupedDump ? (
Expand Down
7 changes: 7 additions & 0 deletions packages/visualizer/src/component/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ export const useChromeTabInfo = create<{
};

Promise.resolve().then(async () => {
if (typeof window.chrome === 'undefined') {
return;
}
const tab = await activeTab();
const windowId = await currentWindowId();
set({
Expand Down Expand Up @@ -206,6 +209,7 @@ export const useExecutionDump = create<{
allExecutionAnimation: AnimationScript[] | null;
sdkVersion: string | null;
modelName: string | null;
modelDescription: string | null;
insightWidth: number | null;
insightHeight: number | null;
activeExecution: ExecutionDump | null;
Expand All @@ -228,6 +232,7 @@ export const useExecutionDump = create<{
allExecutionAnimation: null,
sdkVersion: null,
modelName: null,
modelDescription: null,
insightWidth: null,
insightHeight: null,
activeTask: null,
Expand Down Expand Up @@ -297,6 +302,7 @@ export const useExecutionDump = create<{
width,
height,
modelName,
modelDescription,
sdkVersion,
} = allScriptsInfo;

Expand All @@ -307,6 +313,7 @@ export const useExecutionDump = create<{
insightWidth: width,
insightHeight: height,
modelName,
modelDescription,
sdkVersion,
});
}
Expand Down
7 changes: 3 additions & 4 deletions packages/visualizer/src/extension/scripts/stop-water-flow.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const styleElements = document.querySelectorAll('[id="water-flow-animation"]');
styleElements.forEach((element) => {
document.head.removeChild(element);
});
if (typeof window.midsceneWaterFlowAnimation !== 'undefined') {
window.midsceneWaterFlowAnimation.disable();
}
Loading

0 comments on commit a114e70

Please sign in to comment.