@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.
- package/dist/es/appium.js +2297 -2019
- package/dist/es/chrome-extension.js +1627 -0
- package/dist/es/debug.js +146 -125
- package/dist/es/index.js +2718 -2391
- package/dist/es/midscene-playground.js +1843 -1666
- package/dist/es/playground.js +1368 -1666
- package/dist/es/playwright-report.js +482 -384
- package/dist/es/playwright.js +1616 -1384
- package/dist/es/puppeteer.js +1455 -1244
- package/dist/es/utils.js +599 -0
- package/dist/lib/appium.js +2296 -2003
- package/dist/lib/chrome-extension.js +1627 -0
- package/dist/lib/debug.js +145 -146
- package/dist/lib/index.js +2717 -2375
- package/dist/lib/midscene-playground.js +1843 -1645
- package/dist/lib/playground.js +1367 -1659
- package/dist/lib/playwright-report.js +482 -391
- package/dist/lib/playwright.js +1615 -1384
- package/dist/lib/puppeteer.js +1454 -1243
- package/dist/lib/utils.js +599 -0
- package/dist/script/htmlElement.js +11 -10
- package/dist/script/htmlElementDebug.js +11 -10
- package/dist/types/appium.d.ts +3 -3
- package/dist/types/chrome-extension.d.ts +16 -0
- package/dist/types/debug.d.ts +3 -2
- package/dist/types/index.d.ts +3 -3
- package/dist/types/{page-ad820b3c.d.ts → page-84b18c7f.d.ts} +82 -14
- package/dist/types/playground.d.ts +7 -21
- package/dist/types/playwright.d.ts +3 -4
- package/dist/types/puppeteer.d.ts +3 -3
- package/dist/types/{tasks-82c1054b.d.ts → tasks-bf894fe9.d.ts} +19 -10
- package/dist/types/utils.d.ts +7 -0
- package/package.json +14 -5
- package/static/index.html +0 -245
package/dist/es/debug.js
CHANGED
|
@@ -1,129 +1,150 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
NodeType,
|
|
16
|
-
TEXT_MAX_SIZE,
|
|
17
|
-
TEXT_SIZE_THRESHOLD
|
|
18
|
-
} from "@midscene/shared/constants";
|
|
19
|
-
|
|
20
|
-
// src/debug/index.ts
|
|
21
|
-
import {
|
|
22
|
-
processImageElementInfo,
|
|
23
|
-
resizeImg,
|
|
24
|
-
saveBase64Image
|
|
25
|
-
} from "@midscene/shared/img";
|
|
26
|
-
async function generateExtractData(page, targetDir, saveImgType) {
|
|
27
|
-
const file = await page.screenshot();
|
|
28
|
-
const screenshotBuffer = readFileSync(file);
|
|
29
|
-
const inputImgBase64 = screenshotBuffer.toString("base64");
|
|
30
|
-
const {
|
|
31
|
-
elementsPositionInfo,
|
|
32
|
-
captureElementSnapshot,
|
|
33
|
-
elementsPositionInfoWithoutText
|
|
34
|
-
} = await getElementInfos(page);
|
|
35
|
-
const inputImagePath = path.join(targetDir, "input.png");
|
|
36
|
-
const outputImagePath = path.join(targetDir, "output.png");
|
|
37
|
-
const outputWithoutTextImgPath = path.join(
|
|
38
|
-
targetDir,
|
|
39
|
-
"output_without_text.png"
|
|
40
|
-
);
|
|
41
|
-
const resizeOutputImgPath = path.join(targetDir, "resize-output.png");
|
|
42
|
-
const snapshotJsonPath = path.join(targetDir, "element-snapshot.json");
|
|
43
|
-
const {
|
|
44
|
-
compositeElementInfoImgBase64,
|
|
45
|
-
compositeElementInfoImgWithoutTextBase64
|
|
46
|
-
} = await processImageElementInfo({
|
|
47
|
-
elementsPositionInfo,
|
|
48
|
-
elementsPositionInfoWithoutText,
|
|
49
|
-
inputImgBase64
|
|
50
|
-
});
|
|
51
|
-
const resizeImgBase64 = await resizeImg(inputImgBase64);
|
|
52
|
-
const existingSnapshot = existsSync(snapshotJsonPath) ? JSON.parse(readFileSync(snapshotJsonPath, "utf-8")) : null;
|
|
53
|
-
if (existingSnapshot && JSON.stringify(existingSnapshot) === JSON.stringify(captureElementSnapshot)) {
|
|
54
|
-
console.log("skip save snapshot for ", targetDir);
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
if (!(saveImgType == null ? void 0 : saveImgType.disableSnapshot)) {
|
|
58
|
-
writeFileSyncWithDir(
|
|
59
|
-
snapshotJsonPath,
|
|
60
|
-
JSON.stringify(captureElementSnapshot, null, 2)
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
if (!(saveImgType == null ? void 0 : saveImgType.disableInputImage)) {
|
|
64
|
-
await saveBase64Image({
|
|
65
|
-
base64Data: inputImgBase64,
|
|
66
|
-
outputPath: inputImagePath
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
if (!(saveImgType == null ? void 0 : saveImgType.disableOutputImage)) {
|
|
70
|
-
await saveBase64Image({
|
|
71
|
-
base64Data: compositeElementInfoImgBase64,
|
|
72
|
-
outputPath: outputImagePath
|
|
1
|
+
(function(global, factory) {
|
|
2
|
+
if (typeof module === "object" && typeof module.exports === "object") factory(exports, require("fs"), require("path"), require("@midscene/shared/constants"), require("@midscene/shared/img"));
|
|
3
|
+
else if (typeof define === "function" && define.amd) define([
|
|
4
|
+
"exports",
|
|
5
|
+
"fs",
|
|
6
|
+
"path",
|
|
7
|
+
"@midscene/shared/constants",
|
|
8
|
+
"@midscene/shared/img"
|
|
9
|
+
], factory);
|
|
10
|
+
else if (global = typeof globalThis !== "undefined" ? globalThis : global || self) factory(global.debug = {}, global.fs, global.path, global.constants, global.img);
|
|
11
|
+
})(this, function(exports, _fs, _path, _constants, _img) {
|
|
12
|
+
"use strict";
|
|
13
|
+
Object.defineProperty(exports, "__esModule", {
|
|
14
|
+
value: true
|
|
73
15
|
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
16
|
+
function _export(target, all) {
|
|
17
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: all[name]
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
_export(exports, {
|
|
23
|
+
generateExtractData: function() {
|
|
24
|
+
return generateExtractData;
|
|
25
|
+
},
|
|
26
|
+
generateTestDataPath: function() {
|
|
27
|
+
return generateTestDataPath;
|
|
28
|
+
},
|
|
29
|
+
getElementInfos: function() {
|
|
30
|
+
return getElementInfos;
|
|
31
|
+
},
|
|
32
|
+
writeFileSyncWithDir: function() {
|
|
33
|
+
return writeFileSyncWithDir;
|
|
34
|
+
}
|
|
79
35
|
});
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
36
|
+
_path = /*#__PURE__*/ _interop_require_default(_path);
|
|
37
|
+
function _interop_require_default(obj) {
|
|
38
|
+
return obj && obj.__esModule ? obj : {
|
|
39
|
+
default: obj
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
var __require = /* @__PURE__ */ ((x)=>typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
43
|
+
get: (a, b)=>(typeof require !== "undefined" ? require : a)[b]
|
|
44
|
+
}) : x)(function(x) {
|
|
45
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
46
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
85
47
|
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
48
|
+
var __async = (__this, __arguments, generator)=>{
|
|
49
|
+
return new Promise((resolve, reject)=>{
|
|
50
|
+
var fulfilled = (value)=>{
|
|
51
|
+
try {
|
|
52
|
+
step(generator.next(value));
|
|
53
|
+
} catch (e) {
|
|
54
|
+
reject(e);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
var rejected = (value)=>{
|
|
58
|
+
try {
|
|
59
|
+
step(generator.throw(value));
|
|
60
|
+
} catch (e) {
|
|
61
|
+
reject(e);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var step = (x)=>x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
65
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
function generateExtractData(page, targetDir, saveImgType) {
|
|
69
|
+
return __async(this, null, function*() {
|
|
70
|
+
const inputImgBase64 = yield page.screenshotBase64();
|
|
71
|
+
const { elementsPositionInfo, captureElementSnapshot, elementsPositionInfoWithoutText } = yield getElementInfos(page);
|
|
72
|
+
const inputImagePath = _path.default.join(targetDir, "input.png");
|
|
73
|
+
const outputImagePath = _path.default.join(targetDir, "output.png");
|
|
74
|
+
const outputWithoutTextImgPath = _path.default.join(targetDir, "output_without_text.png");
|
|
75
|
+
const resizeOutputImgPath = _path.default.join(targetDir, "resize-output.png");
|
|
76
|
+
const snapshotJsonPath = _path.default.join(targetDir, "element-snapshot.json");
|
|
77
|
+
const { compositeElementInfoImgBase64, compositeElementInfoImgWithoutTextBase64 } = yield (0, _img.processImageElementInfo)({
|
|
78
|
+
elementsPositionInfo,
|
|
79
|
+
elementsPositionInfoWithoutText,
|
|
80
|
+
inputImgBase64
|
|
81
|
+
});
|
|
82
|
+
const resizedImg = yield (0, _img.resizeImgBase64)(inputImgBase64, void 0);
|
|
83
|
+
const existingSnapshot = (0, _fs.existsSync)(snapshotJsonPath) ? JSON.parse((0, _fs.readFileSync)(snapshotJsonPath, "utf-8")) : null;
|
|
84
|
+
if (existingSnapshot && JSON.stringify(existingSnapshot) === JSON.stringify(captureElementSnapshot)) {
|
|
85
|
+
console.log("skip save snapshot for ", targetDir);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (!(saveImgType == null ? void 0 : saveImgType.disableSnapshot)) {
|
|
89
|
+
writeFileSyncWithDir(snapshotJsonPath, JSON.stringify(captureElementSnapshot, null, 2));
|
|
90
|
+
}
|
|
91
|
+
if (!(saveImgType == null ? void 0 : saveImgType.disableInputImage)) {
|
|
92
|
+
yield (0, _img.saveBase64Image)({
|
|
93
|
+
base64Data: inputImgBase64,
|
|
94
|
+
outputPath: inputImagePath
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (!(saveImgType == null ? void 0 : saveImgType.disableOutputImage)) {
|
|
98
|
+
yield (0, _img.saveBase64Image)({
|
|
99
|
+
base64Data: compositeElementInfoImgBase64,
|
|
100
|
+
outputPath: outputImagePath
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (!(saveImgType == null ? void 0 : saveImgType.disableOutputWithoutTextImg)) {
|
|
104
|
+
yield (0, _img.saveBase64Image)({
|
|
105
|
+
base64Data: compositeElementInfoImgWithoutTextBase64,
|
|
106
|
+
outputPath: outputWithoutTextImgPath
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
if (!(saveImgType == null ? void 0 : saveImgType.disableResizeOutputImg)) {
|
|
110
|
+
yield (0, _img.saveBase64Image)({
|
|
111
|
+
base64Data: resizedImg,
|
|
112
|
+
outputPath: resizeOutputImgPath
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function generateTestDataPath(testDataName) {
|
|
118
|
+
const modulePath = __require.resolve("@midscene/core").replace("dist/lib/index.js", "");
|
|
119
|
+
const midsceneTestDataPath = _path.default.join(modulePath, `tests/ai/evaluate/test-data/${testDataName}`);
|
|
120
|
+
return midsceneTestDataPath;
|
|
116
121
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
122
|
+
function ensureDirectoryExistence(filePath) {
|
|
123
|
+
const dirname = _path.default.dirname(filePath);
|
|
124
|
+
if ((0, _fs.existsSync)(dirname)) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
ensureDirectoryExistence(dirname);
|
|
128
|
+
(0, _fs.mkdirSync)(dirname);
|
|
129
|
+
}
|
|
130
|
+
function writeFileSyncWithDir(filePath, content, options = {}) {
|
|
131
|
+
ensureDirectoryExistence(filePath);
|
|
132
|
+
(0, _fs.writeFileSync)(filePath, content, options);
|
|
133
|
+
}
|
|
134
|
+
function getElementInfos(page) {
|
|
135
|
+
return __async(this, null, function*() {
|
|
136
|
+
const captureElementSnapshot = yield page.getElementInfos();
|
|
137
|
+
const elementsPositionInfoWithoutText = captureElementSnapshot.filter((elementInfo)=>{
|
|
138
|
+
if (elementInfo.attributes.nodeType === _constants.NodeType.TEXT) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
return true;
|
|
142
|
+
});
|
|
143
|
+
return {
|
|
144
|
+
elementsPositionInfo: captureElementSnapshot,
|
|
145
|
+
captureElementSnapshot,
|
|
146
|
+
elementsPositionInfoWithoutText
|
|
147
|
+
};
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
});
|