@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.js CHANGED
@@ -429,13 +429,25 @@ async function screenshotBase64(ctx) {
429
429
  return `data:image/png;base64,${(await screenshotPng(ctx)).toString("base64")}`;
430
430
  }
431
431
  async function dumpUiXml(ctx) {
432
- const raw = await adbShell(ctx, ["uiautomator", "dump", "/dev/tty"], {
432
+ const dumpPath = `/data/local/tmp/android-toolkit-window-${Date.now()}-${Math.random().toString(16).slice(2)}.xml`;
433
+ await adbShell(ctx, ["rm", "-f", dumpPath], { timeoutMs: 1e4 }).catch(() => {
434
+ });
435
+ await adbShell(ctx, ["uiautomator", "dump", dumpPath], {
433
436
  timeoutMs: 3e4,
434
- maxBuffer: 16 * 1024 * 1024
437
+ maxBuffer: 4 * 1024 * 1024
435
438
  });
436
- const start = String(raw || "").indexOf("<?xml");
437
- if (start < 0) throw new CrawlerError({ message: `automation_failed: uiautomator dump missing xml: ${raw}`, code: Code.AutomationFailed });
438
- return String(raw || "").slice(start).trim();
439
+ try {
440
+ const raw = await adbShell(ctx, ["cat", dumpPath], {
441
+ timeoutMs: 3e4,
442
+ maxBuffer: 16 * 1024 * 1024
443
+ });
444
+ const start = String(raw || "").indexOf("<?xml");
445
+ if (start < 0) throw new CrawlerError({ message: `automation_failed: uiautomator dump missing xml: ${raw}`, code: Code.AutomationFailed });
446
+ return String(raw || "").slice(start).trim();
447
+ } finally {
448
+ await adbShell(ctx, ["rm", "-f", dumpPath], { timeoutMs: 1e4 }).catch(() => {
449
+ });
450
+ }
439
451
  }
440
452
  async function wakeAndUnlock(ctx) {
441
453
  await pressKey(ctx, "KEYCODE_WAKEUP").catch(() => {