@skrillex1224/android-toolkit 0.1.1 → 0.1.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skrillex1224/android-toolkit",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -4,7 +4,7 @@ import {spawn} from 'node:child_process';
4
4
  import {Code} from './constants.js';
5
5
  import {adbShell} from './device.js';
6
6
  import {CrawlerError} from './errors.js';
7
- import {Logger} from './logger.js';
7
+ import {Logger, sleep} from './logger.js';
8
8
 
9
9
  /**
10
10
  * 启动一个持续运行的 Frida WebView 事件记录器。
@@ -54,6 +54,22 @@ export async function startWebViewEventRecorder(ctx, config = {}, options = {})
54
54
  * 收集输出和错误显式化。
55
55
  */
56
56
  export async function runScript(ctx, source, options = {}) {
57
+ const attempts = Math.max(1, Number(options.attempts || 3));
58
+ let lastError = null;
59
+ for (let attempt = 1; attempt <= attempts; attempt += 1) {
60
+ try {
61
+ return await runScriptOnce(ctx, source, options);
62
+ } catch (error) {
63
+ lastError = error;
64
+ if (attempt >= attempts || error?.code !== Code.FridaUnavailable) throw error;
65
+ Logger.warn(`frida ${options.label || 'script'} 第 ${attempt} 次未返回,准备重试`);
66
+ await sleep(Number(options.retryDelayMs || 800));
67
+ }
68
+ }
69
+ throw lastError;
70
+ }
71
+
72
+ async function runScriptOnce(ctx, source, options = {}) {
57
73
  assertFridaReady(ctx, ctx.fridaWebViewEventAgentScript, 'frida webview event agent script');
58
74
  const marker = options.marker || 'ANDROID_TOOLKIT_SCRIPT_JSON ';
59
75
  const scriptPath = writeTempScript(ctx, source, options.label || 'script');