@skrillex1224/android-toolkit 1.0.2 → 1.0.3
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/index.cjs +17 -5
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +17 -5
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -458,13 +458,25 @@ async function screenshotBase64(ctx) {
|
|
|
458
458
|
return `data:image/png;base64,${(await screenshotPng(ctx)).toString("base64")}`;
|
|
459
459
|
}
|
|
460
460
|
async function dumpUiXml(ctx) {
|
|
461
|
-
const
|
|
461
|
+
const dumpPath = `/data/local/tmp/android-toolkit-window-${Date.now()}-${Math.random().toString(16).slice(2)}.xml`;
|
|
462
|
+
await adbShell(ctx, ["rm", "-f", dumpPath], { timeoutMs: 1e4 }).catch(() => {
|
|
463
|
+
});
|
|
464
|
+
await adbShell(ctx, ["uiautomator", "dump", dumpPath], {
|
|
462
465
|
timeoutMs: 3e4,
|
|
463
|
-
maxBuffer:
|
|
466
|
+
maxBuffer: 4 * 1024 * 1024
|
|
464
467
|
});
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
+
try {
|
|
469
|
+
const raw = await adbShell(ctx, ["cat", dumpPath], {
|
|
470
|
+
timeoutMs: 3e4,
|
|
471
|
+
maxBuffer: 16 * 1024 * 1024
|
|
472
|
+
});
|
|
473
|
+
const start = String(raw || "").indexOf("<?xml");
|
|
474
|
+
if (start < 0) throw new CrawlerError({ message: `automation_failed: uiautomator dump missing xml: ${raw}`, code: Code.AutomationFailed });
|
|
475
|
+
return String(raw || "").slice(start).trim();
|
|
476
|
+
} finally {
|
|
477
|
+
await adbShell(ctx, ["rm", "-f", dumpPath], { timeoutMs: 1e4 }).catch(() => {
|
|
478
|
+
});
|
|
479
|
+
}
|
|
468
480
|
}
|
|
469
481
|
async function wakeAndUnlock(ctx) {
|
|
470
482
|
await pressKey(ctx, "KEYCODE_WAKEUP").catch(() => {
|