@midscene/web 0.7.2 → 0.7.3-beta-20241104100519.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,9 @@
1
- export { P as AppiumAgent } from './tasks-82c1054b.js';
2
- export { P as AppiumPage } from './page-ad820b3c.js';
3
- import '@midscene/core/dist/types/types-ce502a2a';
1
+ export { P as AppiumAgent } from './tasks-bf894fe9.js';
2
+ export { P as AppiumPage } from './page-84b18c7f.js';
4
3
  import '@midscene/core';
5
4
  import '@midscene/shared/fs';
6
5
  import 'playwright';
7
6
  import 'puppeteer';
8
7
  import '@midscene/shared/constants';
8
+ import '@midscene/core/.';
9
9
  import 'webdriverio';
@@ -0,0 +1,16 @@
1
+ import { C as ChromeExtensionProxyPage } from './page-84b18c7f.js';
2
+ export { b as ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED } from './page-84b18c7f.js';
3
+ import { P as PageAgent } from './tasks-bf894fe9.js';
4
+ import 'playwright';
5
+ import 'puppeteer';
6
+ import '@midscene/shared/constants';
7
+ import '@midscene/core';
8
+ import '@midscene/core/.';
9
+ import 'webdriverio';
10
+ import '@midscene/shared/fs';
11
+
12
+ declare class ChromeExtensionProxyPageAgent extends PageAgent {
13
+ constructor(page: ChromeExtensionProxyPage);
14
+ }
15
+
16
+ export { ChromeExtensionProxyPage, ChromeExtensionProxyPageAgent };
@@ -1,9 +1,10 @@
1
1
  import { writeFileSync } from 'node:fs';
2
- import { W as WebPage, E as ElementInfo } from './page-ad820b3c.js';
2
+ import { W as WebPage, E as ElementInfo } from './page-84b18c7f.js';
3
3
  import 'playwright';
4
4
  import 'puppeteer';
5
- import '@midscene/core';
6
5
  import '@midscene/shared/constants';
6
+ import '@midscene/core';
7
+ import '@midscene/core/.';
7
8
  import 'webdriverio';
8
9
 
9
10
  declare function generateExtractData(page: WebPage, targetDir: string, saveImgType?: {
@@ -1,12 +1,12 @@
1
1
  export { PlayWrightAiFixtureType, PlaywrightAiFixture } from './playwright.js';
2
- export { P as AppiumAgent, P as PlaywrightAgent } from './tasks-82c1054b.js';
3
- export { P as AppiumPage } from './page-ad820b3c.js';
2
+ export { P as AppiumAgent, P as PlaywrightAgent } from './tasks-bf894fe9.js';
3
+ export { P as AppiumPage } from './page-84b18c7f.js';
4
+ export { StaticPageAgent } from './playground.js';
4
5
  export { PuppeteerAgent } from './puppeteer.js';
5
6
  export { generateExtractData } from './debug.js';
6
7
  import '@midscene/core/.';
7
8
  import '@playwright/test';
8
9
  import 'playwright';
9
- import '@midscene/core/dist/types/types-ce502a2a';
10
10
  import '@midscene/core';
11
11
  import '@midscene/shared/fs';
12
12
  import 'puppeteer';
@@ -1,12 +1,13 @@
1
1
  import { Page as Page$3 } from 'playwright';
2
2
  import { KeyInput, Page as Page$2 } from 'puppeteer';
3
- import { BaseElement, Rect, UIContext } from '@midscene/core';
4
3
  import { NodeType } from '@midscene/shared/constants';
4
+ import { BaseElement, Rect, UIContext, PlaywrightParserOpt } from '@midscene/core';
5
+ import * as _midscene_core__ from '@midscene/core/.';
5
6
  import { Browser } from 'webdriverio';
6
7
 
7
8
  declare class WebElementInfo implements BaseElement {
8
9
  content: string;
9
- locator: string;
10
+ locator?: string;
10
11
  rect: Rect;
11
12
  center: [number, number];
12
13
  page: WebPage$1;
@@ -20,7 +21,7 @@ declare class WebElementInfo implements BaseElement {
20
21
  content: string;
21
22
  rect: Rect;
22
23
  page: WebPage$1;
23
- locator: string;
24
+ locator?: string;
24
25
  id: string;
25
26
  attributes: {
26
27
  nodeType: NodeType;
@@ -33,6 +34,17 @@ declare class WebElementInfo implements BaseElement {
33
34
  type WebUIContext = UIContext<WebElementInfo> & {
34
35
  url: string;
35
36
  };
37
+ declare function parseContextFromWebPage(page: WebPage$1, _opt?: PlaywrightParserOpt): Promise<WebUIContext>;
38
+ declare function getExtraReturnLogic(): Promise<string>;
39
+ declare function reportFileName(tag?: string): string;
40
+ declare function printReportMsg(filepath: string): void;
41
+ /**
42
+ * Get the current execution file name
43
+ * @returns The name of the current execution file
44
+ */
45
+ declare function getCurrentExecutionFile(trace?: string): string | false;
46
+ declare function generateCacheId(fileName?: string): string;
47
+ declare const ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED = "NOT_IMPLEMENTED_AS_DESIGNED";
36
48
 
37
49
  interface ElementInfo {
38
50
  id: string;
@@ -58,9 +70,14 @@ interface ElementInfo {
58
70
  type MouseButton = 'left' | 'right' | 'middle';
59
71
  declare abstract class AbstractPage {
60
72
  abstract pageType: string;
61
- abstract screenshot(): Promise<string>;
62
73
  abstract getElementInfos(): Promise<ElementInfo[]>;
63
- abstract url(): string;
74
+ abstract url(): string | Promise<string>;
75
+ abstract screenshotBase64?(): Promise<string>;
76
+ abstract size(): Promise<{
77
+ width: number;
78
+ height: number;
79
+ dpr?: number;
80
+ }>;
64
81
  get mouse(): {
65
82
  click: (x: number, y: number, options: {
66
83
  button: MouseButton;
@@ -78,6 +95,7 @@ declare abstract class AbstractPage {
78
95
  abstract scrollUpOneScreen(): Promise<void>;
79
96
  abstract scrollDownOneScreen(): Promise<void>;
80
97
  abstract _forceUsePageContext?(): Promise<WebUIContext>;
98
+ abstract destroy(): Promise<void>;
81
99
  }
82
100
 
83
101
  type WebKeyInput$1 = KeyInput;
@@ -86,7 +104,11 @@ declare class Page$1 implements AbstractPage {
86
104
  pageType: string;
87
105
  constructor(browser: Browser);
88
106
  getElementInfos(): Promise<ElementInfo[]>;
89
- screenshot(): Promise<string>;
107
+ size(): Promise<{
108
+ width: number;
109
+ height: number;
110
+ }>;
111
+ screenshotBase64(): Promise<string>;
90
112
  get mouse(): {
91
113
  click: (x: number, y: number, options?: {
92
114
  button: MouseButton;
@@ -109,6 +131,42 @@ declare class Page$1 implements AbstractPage {
109
131
  private mouseClick;
110
132
  private mouseMove;
111
133
  private mouseWheel;
134
+ destroy(): Promise<void>;
135
+ }
136
+
137
+ declare class ChromeExtensionProxyPage implements AbstractPage {
138
+ pageType: string;
139
+ private tabId;
140
+ private windowId;
141
+ private viewportSize?;
142
+ private debuggerAttached;
143
+ constructor(tabId: number, windowId: number);
144
+ private attachDebugger;
145
+ private detachDebugger;
146
+ private sendCommandToDebugger;
147
+ getElementInfos(): Promise<ElementInfo[]>;
148
+ size(): Promise<{
149
+ width: number;
150
+ height: number;
151
+ dpr: number;
152
+ }>;
153
+ screenshotBase64(): Promise<string>;
154
+ url(): Promise<string>;
155
+ scrollUntilTop(): Promise<void>;
156
+ scrollUntilBottom(): Promise<void>;
157
+ scrollUpOneScreen(): Promise<void>;
158
+ scrollDownOneScreen(): Promise<void>;
159
+ clearInput(element: ElementInfo): Promise<void>;
160
+ mouse: {
161
+ click: (x: number, y: number) => Promise<void>;
162
+ wheel: (deltaX: number, deltaY: number) => Promise<void>;
163
+ move: (x: number, y: number) => Promise<void>;
164
+ };
165
+ keyboard: {
166
+ type: (text: string) => Promise<void>;
167
+ press: (key: WebKeyInput) => Promise<void>;
168
+ };
169
+ destroy(): Promise<void>;
112
170
  }
113
171
 
114
172
  declare class StaticPage implements AbstractPage {
@@ -116,8 +174,9 @@ declare class StaticPage implements AbstractPage {
116
174
  private uiContext;
117
175
  constructor(uiContext: WebUIContext);
118
176
  getElementInfos(): Promise<any>;
119
- screenshot(): Promise<string>;
120
- url(): string;
177
+ size(): Promise<_midscene_core__.Size>;
178
+ screenshotBase64(): Promise<string>;
179
+ url(): Promise<string>;
121
180
  scrollUntilTop(): Promise<any>;
122
181
  scrollUntilBottom(): Promise<any>;
123
182
  scrollUpOneScreen(): Promise<any>;
@@ -133,16 +192,23 @@ declare class StaticPage implements AbstractPage {
133
192
  press: any;
134
193
  };
135
194
  _forceUsePageContext(): Promise<WebUIContext>;
195
+ destroy(): Promise<void>;
136
196
  }
137
197
 
138
198
  declare class Page<AgentType extends 'puppeteer' | 'playwright', PageType extends Page$2 | Page$3> implements AbstractPage {
139
- private page;
199
+ private underlyingPage;
200
+ private viewportSize?;
140
201
  pageType: AgentType;
141
202
  private evaluate;
142
- constructor(page: PageType, pageType: AgentType);
203
+ constructor(underlyingPage: PageType, pageType: AgentType);
143
204
  getElementInfos(): Promise<ElementInfo[]>;
144
- screenshot(): Promise<string>;
145
- url(): string;
205
+ size(): Promise<{
206
+ width: number;
207
+ height: number;
208
+ dpr: number;
209
+ }>;
210
+ screenshotBase64(): Promise<string>;
211
+ url(): Promise<string>;
146
212
  get mouse(): {
147
213
  click: (x: number, y: number, options?: {
148
214
  button: MouseButton;
@@ -161,6 +227,7 @@ declare class Page<AgentType extends 'puppeteer' | 'playwright', PageType extend
161
227
  scrollUntilBottom(): Promise<void>;
162
228
  scrollUpOneScreen(): Promise<void>;
163
229
  scrollDownOneScreen(): Promise<void>;
230
+ destroy(): Promise<void>;
164
231
  }
165
232
 
166
233
  declare class WebPage$2 extends Page<'puppeteer', Page$2> {
@@ -171,11 +238,12 @@ type WebPage$1 =
171
238
  | WebPage
172
239
  | WebPage$2
173
240
  | Page$1
174
- | StaticPage;
241
+ | StaticPage
242
+ | ChromeExtensionProxyPage;
175
243
  type WebKeyInput = KeyInput;
176
244
 
177
245
  declare class WebPage extends Page<'playwright', Page$3> {
178
246
  constructor(page: Page$3);
179
247
  }
180
248
 
181
- export { type ElementInfo as E, Page$1 as P, StaticPage as S, type WebPage$1 as W, WebPage$2 as a, WebPage as b, type WebUIContext as c, WebElementInfo as d };
249
+ export { ChromeExtensionProxyPage as C, type ElementInfo as E, Page$1 as P, StaticPage as S, type WebPage$1 as W, WebPage$2 as a, ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED as b, WebPage as c, type WebUIContext as d, WebElementInfo as e, printReportMsg as f, getExtraReturnLogic as g, getCurrentExecutionFile as h, generateCacheId as i, parseContextFromWebPage as p, reportFileName as r };
@@ -1,30 +1,16 @@
1
- import { P as PageAgent } from './tasks-82c1054b.js';
2
- import { S as StaticPage } from './page-ad820b3c.js';
3
- import * as http from 'http';
4
- import { Server } from 'node:http';
5
- import express from 'express';
6
- import '@midscene/core/dist/types/types-ce502a2a';
7
- import '@midscene/core';
8
- import '@midscene/shared/fs';
1
+ import { S as StaticPage } from './page-84b18c7f.js';
2
+ export { b as ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED } from './page-84b18c7f.js';
3
+ import { P as PageAgent } from './tasks-bf894fe9.js';
9
4
  import 'playwright';
10
5
  import 'puppeteer';
11
6
  import '@midscene/shared/constants';
7
+ import '@midscene/core';
8
+ import '@midscene/core/.';
12
9
  import 'webdriverio';
10
+ import '@midscene/shared/fs';
13
11
 
14
12
  declare class StaticPageAgent extends PageAgent {
15
13
  constructor(page: StaticPage);
16
14
  }
17
15
 
18
- declare class PlaygroundServer {
19
- app: express.Application;
20
- tmpDir: string;
21
- server?: Server;
22
- port?: number | null;
23
- constructor();
24
- filePathForUuid(uuid: string): string;
25
- saveContextFile(uuid: string, context: string): string;
26
- launch(): Promise<unknown>;
27
- close(): Server<typeof http.IncomingMessage, typeof http.ServerResponse> | undefined;
28
- }
29
-
30
- export { PlaygroundServer, StaticPage, StaticPageAgent };
16
+ export { StaticPage, StaticPageAgent };
@@ -1,10 +1,9 @@
1
1
  import { AgentWaitForOpt } from '@midscene/core/.';
2
2
  import { TestInfo } from '@playwright/test';
3
3
  import { Page } from 'playwright';
4
- import { b as PageTaskExecutor } from './tasks-82c1054b.js';
5
- export { P as PlaywrightAgent } from './tasks-82c1054b.js';
6
- export { b as PlaywrightWebPage } from './page-ad820b3c.js';
7
- import '@midscene/core/dist/types/types-ce502a2a';
4
+ import { b as PageTaskExecutor } from './tasks-bf894fe9.js';
5
+ export { P as PlaywrightAgent } from './tasks-bf894fe9.js';
6
+ export { c as PlaywrightWebPage } from './page-84b18c7f.js';
8
7
  import '@midscene/core';
9
8
  import '@midscene/shared/fs';
10
9
  import 'puppeteer';
@@ -1,11 +1,11 @@
1
- import { P as PageAgent, a as PageAgentOpt } from './tasks-82c1054b.js';
1
+ import { P as PageAgent, a as PageAgentOpt } from './tasks-bf894fe9.js';
2
2
  import { Page } from 'puppeteer';
3
- export { a as PuppeteerWebPage } from './page-ad820b3c.js';
4
- import '@midscene/core/dist/types/types-ce502a2a';
3
+ export { a as PuppeteerWebPage } from './page-84b18c7f.js';
5
4
  import '@midscene/core';
6
5
  import '@midscene/shared/fs';
7
6
  import 'playwright';
8
7
  import '@midscene/shared/constants';
8
+ import '@midscene/core/.';
9
9
  import 'webdriverio';
10
10
 
11
11
  declare class PuppeteerAgent extends PageAgent {
@@ -1,7 +1,7 @@
1
- import * as _midscene_core_dist_types_types_ce502a2a from '@midscene/core/dist/types/types-ce502a2a';
2
- import { c as WebUIContext, W as WebPage, d as WebElementInfo } from './page-ad820b3c.js';
3
- import { PlanningAction, AIElementParseResponse, GroupedActionDump, ExecutionDump, AgentAssertOpt, AgentWaitForOpt, Insight, InsightExtractParam, InsightAssertionResponse, PlanningActionParamWaitFor, Executor } from '@midscene/core';
4
- import { getMidscenePkgInfo } from '@midscene/shared/fs';
1
+ import * as _midscene_core from '@midscene/core';
2
+ import { PlanningAction, AIElementIdResponse, Insight, GroupedActionDump, ExecutionDump, AgentAssertOpt, AgentWaitForOpt, InsightExtractParam, InsightAssertionResponse, PlanningActionParamWaitFor, Executor } from '@midscene/core';
3
+ import { d as WebUIContext, W as WebPage, e as WebElementInfo } from './page-84b18c7f.js';
4
+ import { getRunningPkgInfo } from '@midscene/shared/fs';
5
5
 
6
6
  type PlanTask = {
7
7
  type: 'plan';
@@ -27,7 +27,7 @@ type LocateTask = {
27
27
  height: number;
28
28
  };
29
29
  };
30
- response: AIElementParseResponse;
30
+ response: AIElementIdResponse;
31
31
  };
32
32
  type AiTasks = Array<PlanTask | LocateTask>;
33
33
  type AiTaskCache = {
@@ -40,14 +40,14 @@ declare class TaskCache {
40
40
  cache: AiTaskCache;
41
41
  cacheId: string;
42
42
  newCache: AiTaskCache;
43
- midscenePkgInfo: ReturnType<typeof getMidscenePkgInfo>;
43
+ midscenePkgInfo: ReturnType<typeof getRunningPkgInfo> | null;
44
44
  constructor(opts?: {
45
45
  fileName?: string;
46
46
  });
47
47
  getCacheGroupByPrompt(aiActionPrompt: string): {
48
48
  readCache: <T extends "plan" | "locate">(pageContext: WebUIContext, type: T, actionPrompt: string) => false | (T extends "plan" ? {
49
49
  plans: PlanningAction<any>[];
50
- } : AIElementParseResponse);
50
+ } : AIElementIdResponse);
51
51
  saveCache: (cache: PlanTask | LocateTask) => void;
52
52
  };
53
53
  /**
@@ -92,20 +92,29 @@ interface PageAgentOpt {
92
92
  }
93
93
  declare class PageAgent {
94
94
  page: WebPage;
95
+ insight: Insight<WebElementInfo, WebUIContext>;
95
96
  dump: GroupedActionDump;
96
- reportFile?: string;
97
+ reportFile?: string | null;
97
98
  reportFileName?: string;
98
99
  taskExecutor: PageTaskExecutor;
99
100
  opts: PageAgentOpt;
101
+ /**
102
+ * If true, the agent will not perform any actions
103
+ */
104
+ dryMode: boolean;
100
105
  constructor(page: WebPage, opts?: PageAgentOpt);
106
+ getUIContext(): Promise<WebUIContext>;
107
+ resetDump(): GroupedActionDump;
101
108
  appendExecutionDump(execution: ExecutionDump): void;
102
109
  dumpDataString(): string;
110
+ reportHTMLString(): string;
103
111
  writeOutActionDumps(): void;
104
112
  aiAction(taskPrompt: string): Promise<void>;
105
113
  aiQuery(demand: any): Promise<any>;
106
- aiAssert(assertion: string, msg?: string, opt?: AgentAssertOpt): Promise<_midscene_core_dist_types_types_ce502a2a.d | undefined>;
114
+ aiAssert(assertion: string, msg?: string, opt?: AgentAssertOpt): Promise<_midscene_core.AIAssertionResponse | undefined>;
107
115
  aiWaitFor(assertion: string, opt?: AgentWaitForOpt): Promise<void>;
108
116
  ai(taskPrompt: string, type?: string): Promise<any>;
117
+ destroy(): Promise<void>;
109
118
  }
110
119
 
111
120
  interface ExecutionResult<OutputType = any> {
@@ -116,7 +125,7 @@ declare class PageTaskExecutor {
116
125
  page: WebPage;
117
126
  insight: Insight<WebElementInfo, WebUIContext>;
118
127
  taskCache: TaskCache;
119
- constructor(page: WebPage, opts: {
128
+ constructor(page: WebPage, insight: Insight<WebElementInfo, WebUIContext>, opts: {
120
129
  cacheId: string | undefined;
121
130
  });
122
131
  private recordScreenshot;
@@ -0,0 +1,7 @@
1
+ import '@midscene/core';
2
+ export { b as ERROR_CODE_NOT_IMPLEMENTED_AS_DESIGNED, d as WebUIContext, i as generateCacheId, h as getCurrentExecutionFile, g as getExtraReturnLogic, p as parseContextFromWebPage, f as printReportMsg, r as reportFileName } from './page-84b18c7f.js';
3
+ import 'playwright';
4
+ import 'puppeteer';
5
+ import '@midscene/shared/constants';
6
+ import '@midscene/core/.';
7
+ import 'webdriverio';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@midscene/web",
3
3
  "description": "An AI-powered automation SDK can control the page, perform assertions, and extract data in JSON format using natural language. See https://midscenejs.com/ for details.",
4
- "version": "0.7.2",
4
+ "version": "0.7.3-beta-20241104100519.0",
5
5
  "repository": "https://github.com/web-infra-dev/midscene",
6
6
  "homepage": "https://midscenejs.com/",
7
7
  "jsnext:source": "./src/index.ts",
@@ -12,19 +12,24 @@
12
12
  },
13
13
  "exports": {
14
14
  ".": "./dist/lib/index.js",
15
+ "./utils": "./dist/lib/utils.js",
15
16
  "./puppeteer": "./dist/lib/puppeteer.js",
16
17
  "./playwright": "./dist/lib/playwright.js",
17
18
  "./playwright-report": "./dist/lib/playwright-report.js",
18
19
  "./playground": "./dist/lib/playground.js",
19
20
  "./debug": "./dist/lib/debug.js",
20
21
  "./constants": "./dist/lib/constants.js",
21
- "./html-element": "./dist/lib/html-element/index.js"
22
+ "./html-element": "./dist/lib/html-element/index.js",
23
+ "./chrome-extension": "./dist/lib/chrome-extension.js"
22
24
  },
23
25
  "typesVersions": {
24
26
  "*": {
25
27
  ".": [
26
28
  "./dist/types/index.d.ts"
27
29
  ],
30
+ "utils": [
31
+ "./dist/types/utils.d.ts"
32
+ ],
28
33
  "puppeteer": [
29
34
  "./dist/types/puppeteer.d.ts"
30
35
  ],
@@ -45,6 +50,9 @@
45
50
  ],
46
51
  "html-element": [
47
52
  "./dist/types/html-element/index.d.ts"
53
+ ],
54
+ "chrome-extension": [
55
+ "./dist/types/chrome-extension.d.ts"
48
56
  ]
49
57
  }
50
58
  },
@@ -60,12 +68,13 @@
60
68
  "inquirer": "10.1.5",
61
69
  "cors": "2.8.5",
62
70
  "@xmldom/xmldom": "0.8.10",
63
- "@midscene/shared": "0.7.2",
64
- "@midscene/core": "0.7.2"
71
+ "@midscene/shared": "0.7.3-beta-20241104100519.0",
72
+ "@midscene/core": "0.7.3-beta-20241104100519.0"
65
73
  },
66
74
  "devDependencies": {
67
- "@modern-js/module-tools": "2.58.2",
75
+ "@modern-js/module-tools": "2.60.6",
68
76
  "@playwright/test": "1.44.1",
77
+ "@types/chrome": "0.0.279",
69
78
  "@types/cors": "2.8.12",
70
79
  "@types/fs-extra": "11.0.4",
71
80
  "@types/node": "^18.0.0",