@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.js CHANGED
@@ -215,9 +215,6 @@ var Logger = {
215
215
  return `${((Date.now() - startedAt) / 1e3).toFixed(2)}s`;
216
216
  }
217
217
  };
218
- function stripAnsi(value) {
219
- return String(value || "").replace(/\u001b\[[0-9;]*m/g, "");
220
- }
221
218
  function sleep(ms) {
222
219
  return new Promise((resolve) => setTimeout(resolve, ms));
223
220
  }
@@ -432,13 +429,25 @@ async function screenshotBase64(ctx) {
432
429
  return `data:image/png;base64,${(await screenshotPng(ctx)).toString("base64")}`;
433
430
  }
434
431
  async function dumpUiXml(ctx) {
435
- 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], {
436
436
  timeoutMs: 3e4,
437
- maxBuffer: 16 * 1024 * 1024
437
+ maxBuffer: 4 * 1024 * 1024
438
438
  });
439
- const start = String(raw || "").indexOf("<?xml");
440
- if (start < 0) throw new CrawlerError({ message: `automation_failed: uiautomator dump missing xml: ${raw}`, code: Code.AutomationFailed });
441
- 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
+ }
442
451
  }
443
452
  async function wakeAndUnlock(ctx) {
444
453
  await pressKey(ctx, "KEYCODE_WAKEUP").catch(() => {
@@ -1868,11 +1877,7 @@ var useAndroidToolKit = () => ({
1868
1877
  Constants: constants_exports,
1869
1878
  Errors: errors_exports,
1870
1879
  Logger,
1871
- Context,
1872
- $Internals: {
1873
- LOG_TEMPLATES,
1874
- stripAnsi
1875
- }
1880
+ Context
1876
1881
  });
1877
1882
  export {
1878
1883
  useAndroidToolKit