@midscene/android 0.22.1-beta-20250717053953.0 → 0.22.1
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/index.js +18 -21
- package/dist/lib/index.js +18 -21
- package/package.json +4 -4
package/dist/es/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// src/page/index.ts
|
|
2
2
|
import assert from "assert";
|
|
3
|
+
import { randomUUID } from "crypto";
|
|
3
4
|
import fs from "fs";
|
|
4
5
|
import path from "path";
|
|
5
6
|
import { getAIConfig } from "@midscene/core";
|
|
@@ -14,7 +15,6 @@ import { isValidPNGImageBuffer, resizeImg } from "@midscene/shared/img";
|
|
|
14
15
|
import { getDebug } from "@midscene/shared/logger";
|
|
15
16
|
import { repeat } from "@midscene/shared/utils";
|
|
16
17
|
import { ADB } from "appium-adb";
|
|
17
|
-
var androidScreenshotPath = "/data/local/tmp/midscene_screenshot.png";
|
|
18
18
|
var defaultScrollUntilTimes = 10;
|
|
19
19
|
var defaultFastScrollDuration = 100;
|
|
20
20
|
var defaultNormalScrollDuration = 1e3;
|
|
@@ -239,34 +239,32 @@ ${Object.keys(size).filter((key) => size[key]).map(
|
|
|
239
239
|
const { width, height } = await this.size();
|
|
240
240
|
const adb = await this.getAdb();
|
|
241
241
|
let screenshotBuffer;
|
|
242
|
+
const androidScreenshotPath = `/data/local/tmp/midscene_screenshot_${randomUUID()}.png`;
|
|
242
243
|
try {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
244
|
+
screenshotBuffer = await adb.takeScreenshot(null);
|
|
245
|
+
if (!screenshotBuffer) {
|
|
246
|
+
throw new Error(
|
|
247
|
+
"Failed to capture screenshot: screenshotBuffer is null"
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
if (!isValidPNGImageBuffer(screenshotBuffer)) {
|
|
251
|
+
debugPage("Invalid image buffer detected: not a valid image format");
|
|
252
|
+
throw new Error(
|
|
253
|
+
"Screenshot buffer has invalid format: could not find valid image signature"
|
|
254
|
+
);
|
|
255
|
+
}
|
|
247
256
|
} catch (error) {
|
|
257
|
+
const screenshotPath = getTmpFile("png");
|
|
248
258
|
try {
|
|
249
|
-
screenshotBuffer = await adb.takeScreenshot(null);
|
|
250
|
-
if (!screenshotBuffer) {
|
|
251
|
-
throw new Error(
|
|
252
|
-
"Failed to capture screenshot: screenshotBuffer is null"
|
|
253
|
-
);
|
|
254
|
-
}
|
|
255
|
-
if (!isValidPNGImageBuffer(screenshotBuffer)) {
|
|
256
|
-
debugPage("Invalid image buffer detected: not a valid image format");
|
|
257
|
-
throw new Error(
|
|
258
|
-
"Screenshot buffer has invalid format: could not find valid image signature"
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
} catch (fallbackError) {
|
|
262
|
-
const screenshotPath = getTmpFile("png");
|
|
263
259
|
try {
|
|
264
260
|
await adb.shell(`screencap -p ${androidScreenshotPath}`);
|
|
265
261
|
} catch (error2) {
|
|
266
|
-
|
|
262
|
+
await this.forceScreenshot(androidScreenshotPath);
|
|
267
263
|
}
|
|
268
264
|
await adb.pull(androidScreenshotPath, screenshotPath);
|
|
269
265
|
screenshotBuffer = await fs.promises.readFile(screenshotPath);
|
|
266
|
+
} finally {
|
|
267
|
+
await adb.shell(`rm -f ${androidScreenshotPath}`);
|
|
270
268
|
}
|
|
271
269
|
}
|
|
272
270
|
const resizedScreenshotBuffer = await resizeImg(screenshotBuffer, {
|
|
@@ -526,7 +524,6 @@ ${Object.keys(size).filter((key) => size[key]).map(
|
|
|
526
524
|
this.destroyed = true;
|
|
527
525
|
try {
|
|
528
526
|
if (this.adb) {
|
|
529
|
-
await this.adb.shell(`rm -f ${androidScreenshotPath}`);
|
|
530
527
|
this.adb = null;
|
|
531
528
|
}
|
|
532
529
|
} catch (error) {
|
package/dist/lib/index.js
CHANGED
|
@@ -40,6 +40,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
40
40
|
|
|
41
41
|
// src/page/index.ts
|
|
42
42
|
var import_node_assert = __toESM(require("assert"));
|
|
43
|
+
var import_node_crypto = require("crypto");
|
|
43
44
|
var import_node_fs = __toESM(require("fs"));
|
|
44
45
|
var import_node_path = __toESM(require("path"));
|
|
45
46
|
var import_core = require("@midscene/core");
|
|
@@ -49,7 +50,6 @@ var import_img = require("@midscene/shared/img");
|
|
|
49
50
|
var import_logger = require("@midscene/shared/logger");
|
|
50
51
|
var import_utils2 = require("@midscene/shared/utils");
|
|
51
52
|
var import_appium_adb = require("appium-adb");
|
|
52
|
-
var androidScreenshotPath = "/data/local/tmp/midscene_screenshot.png";
|
|
53
53
|
var defaultScrollUntilTimes = 10;
|
|
54
54
|
var defaultFastScrollDuration = 100;
|
|
55
55
|
var defaultNormalScrollDuration = 1e3;
|
|
@@ -274,34 +274,32 @@ ${Object.keys(size).filter((key) => size[key]).map(
|
|
|
274
274
|
const { width, height } = await this.size();
|
|
275
275
|
const adb = await this.getAdb();
|
|
276
276
|
let screenshotBuffer;
|
|
277
|
+
const androidScreenshotPath = `/data/local/tmp/midscene_screenshot_${(0, import_node_crypto.randomUUID)()}.png`;
|
|
277
278
|
try {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
279
|
+
screenshotBuffer = await adb.takeScreenshot(null);
|
|
280
|
+
if (!screenshotBuffer) {
|
|
281
|
+
throw new Error(
|
|
282
|
+
"Failed to capture screenshot: screenshotBuffer is null"
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
if (!(0, import_img.isValidPNGImageBuffer)(screenshotBuffer)) {
|
|
286
|
+
debugPage("Invalid image buffer detected: not a valid image format");
|
|
287
|
+
throw new Error(
|
|
288
|
+
"Screenshot buffer has invalid format: could not find valid image signature"
|
|
289
|
+
);
|
|
290
|
+
}
|
|
282
291
|
} catch (error) {
|
|
292
|
+
const screenshotPath = (0, import_utils.getTmpFile)("png");
|
|
283
293
|
try {
|
|
284
|
-
screenshotBuffer = await adb.takeScreenshot(null);
|
|
285
|
-
if (!screenshotBuffer) {
|
|
286
|
-
throw new Error(
|
|
287
|
-
"Failed to capture screenshot: screenshotBuffer is null"
|
|
288
|
-
);
|
|
289
|
-
}
|
|
290
|
-
if (!(0, import_img.isValidPNGImageBuffer)(screenshotBuffer)) {
|
|
291
|
-
debugPage("Invalid image buffer detected: not a valid image format");
|
|
292
|
-
throw new Error(
|
|
293
|
-
"Screenshot buffer has invalid format: could not find valid image signature"
|
|
294
|
-
);
|
|
295
|
-
}
|
|
296
|
-
} catch (fallbackError) {
|
|
297
|
-
const screenshotPath = (0, import_utils.getTmpFile)("png");
|
|
298
294
|
try {
|
|
299
295
|
await adb.shell(`screencap -p ${androidScreenshotPath}`);
|
|
300
296
|
} catch (error2) {
|
|
301
|
-
|
|
297
|
+
await this.forceScreenshot(androidScreenshotPath);
|
|
302
298
|
}
|
|
303
299
|
await adb.pull(androidScreenshotPath, screenshotPath);
|
|
304
300
|
screenshotBuffer = await import_node_fs.default.promises.readFile(screenshotPath);
|
|
301
|
+
} finally {
|
|
302
|
+
await adb.shell(`rm -f ${androidScreenshotPath}`);
|
|
305
303
|
}
|
|
306
304
|
}
|
|
307
305
|
const resizedScreenshotBuffer = await (0, import_img.resizeImg)(screenshotBuffer, {
|
|
@@ -561,7 +559,6 @@ ${Object.keys(size).filter((key) => size[key]).map(
|
|
|
561
559
|
this.destroyed = true;
|
|
562
560
|
try {
|
|
563
561
|
if (this.adb) {
|
|
564
|
-
await this.adb.shell(`rm -f ${androidScreenshotPath}`);
|
|
565
562
|
this.adb = null;
|
|
566
563
|
}
|
|
567
564
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/android",
|
|
3
|
-
"version": "0.22.1
|
|
3
|
+
"version": "0.22.1",
|
|
4
4
|
"description": "Android automation library for Midscene",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Android UI automation",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"appium-adb": "12.12.1",
|
|
27
|
-
"@midscene/
|
|
28
|
-
"@midscene/
|
|
29
|
-
"@midscene/
|
|
27
|
+
"@midscene/core": "0.22.1",
|
|
28
|
+
"@midscene/web": "0.22.1",
|
|
29
|
+
"@midscene/shared": "0.22.1"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@modern-js/module-tools": "2.60.6",
|