@skrillex1224/android-toolkit 1.0.1 → 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 +18 -13
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +18 -13
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -244,9 +244,6 @@ var Logger = {
|
|
|
244
244
|
return `${((Date.now() - startedAt) / 1e3).toFixed(2)}s`;
|
|
245
245
|
}
|
|
246
246
|
};
|
|
247
|
-
function stripAnsi(value) {
|
|
248
|
-
return String(value || "").replace(/\u001b\[[0-9;]*m/g, "");
|
|
249
|
-
}
|
|
250
247
|
function sleep(ms) {
|
|
251
248
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
252
249
|
}
|
|
@@ -461,13 +458,25 @@ async function screenshotBase64(ctx) {
|
|
|
461
458
|
return `data:image/png;base64,${(await screenshotPng(ctx)).toString("base64")}`;
|
|
462
459
|
}
|
|
463
460
|
async function dumpUiXml(ctx) {
|
|
464
|
-
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], {
|
|
465
465
|
timeoutMs: 3e4,
|
|
466
|
-
maxBuffer:
|
|
466
|
+
maxBuffer: 4 * 1024 * 1024
|
|
467
467
|
});
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
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
|
+
}
|
|
471
480
|
}
|
|
472
481
|
async function wakeAndUnlock(ctx) {
|
|
473
482
|
await pressKey(ctx, "KEYCODE_WAKEUP").catch(() => {
|
|
@@ -1897,11 +1906,7 @@ var useAndroidToolKit = () => ({
|
|
|
1897
1906
|
Constants: constants_exports,
|
|
1898
1907
|
Errors: errors_exports,
|
|
1899
1908
|
Logger,
|
|
1900
|
-
Context
|
|
1901
|
-
$Internals: {
|
|
1902
|
-
LOG_TEMPLATES,
|
|
1903
|
-
stripAnsi
|
|
1904
|
-
}
|
|
1909
|
+
Context
|
|
1905
1910
|
});
|
|
1906
1911
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1907
1912
|
0 && (module.exports = {
|