@weapp-vite/miniprogram-automator 1.2.2 → 1.2.4

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.d.mts CHANGED
@@ -232,6 +232,7 @@ declare class Page {
232
232
  //#region src/MiniProgram.d.ts
233
233
  interface IScreenshotOptions {
234
234
  path?: string;
235
+ timeout?: number;
235
236
  }
236
237
  interface IAuditsOptions {
237
238
  path?: string;
@@ -281,7 +282,7 @@ declare class MiniProgram extends EventEmitter {
281
282
  * @description 等待小程序 App 域协议可用,避免返回半就绪自动化会话。
282
283
  */
283
284
  waitForAppReady(timeout?: number): Promise<void>;
284
- screenshot(options?: IScreenshotOptions): Promise<any>;
285
+ screenshot(options?: IScreenshotOptions): Promise<string | undefined>;
285
286
  testAccounts(): Promise<any>;
286
287
  /**
287
288
  * @description 获取开发者工具 Tool 域基础信息。
@@ -413,7 +414,7 @@ declare class SmartappApp {
413
414
  retry?: number;
414
415
  timeout?: number;
415
416
  }): Promise<SmartappPage>;
416
- screenshot(options?: ScreenshotOptions): Promise<any>;
417
+ screenshot(options?: ScreenshotOptions): Promise<string | undefined>;
417
418
  currentPage(): Promise<SmartappPage>;
418
419
  data(): Promise<any>;
419
420
  tabs(): Promise<never[]>;
@@ -557,9 +558,9 @@ declare function decodeQrCode(qrCode: string): Promise<string>;
557
558
  /** printQrCode 的方法封装。 */
558
559
  declare function printQrCode(content: string): Promise<void>;
559
560
  /** isPluginPath 的方法封装。 */
560
- declare function isPluginPath(p: string): boolean;
561
+ declare function isPluginPath(p: unknown): boolean;
561
562
  /** extractPluginId 的方法封装。 */
562
- declare function extractPluginId(p: string): string;
563
+ declare function extractPluginId(p: unknown): string;
563
564
  //#endregion
564
565
  //#region src/index.d.ts
565
566
  declare const SmartappAutomator: {
package/dist/index.mjs CHANGED
@@ -683,7 +683,7 @@ async function acquireAutomatorPortLease(preferredPort) {
683
683
  }
684
684
  //#endregion
685
685
  //#region package.json
686
- var version = "1.2.2";
686
+ var version = "1.2.4";
687
687
  //#endregion
688
688
  //#region src/Native.ts
689
689
  /** Native 的实现。 */
@@ -864,10 +864,12 @@ function printQrCode(content) {
864
864
  }
865
865
  /** isPluginPath 的方法封装。 */
866
866
  function isPluginPath(p) {
867
+ if (typeof p !== "string") return false;
867
868
  return startWith(p, "plugin-private://");
868
869
  }
869
870
  /** extractPluginId 的方法封装。 */
870
871
  function extractPluginId(p) {
872
+ if (typeof p !== "string") return "";
871
873
  const match = p.match(regPluginId);
872
874
  return match ? match[1] : "";
873
875
  }
@@ -883,6 +885,8 @@ const CHANGE_ROUTE_POLL_DELAY = 500;
883
885
  const APP_READY_TIMEOUT = 2e4;
884
886
  const APP_READY_PROBE_TIMEOUT = 3e3;
885
887
  const APP_READY_POLL_DELAY = 500;
888
+ const SCREENSHOT_RETRIES = 2;
889
+ const SCREENSHOT_RETRY_DELAY = 500;
886
890
  const CHANGE_ROUTE_DEBUG_ENABLED = process.env.WEAPP_VITE_E2E_CHANGE_ROUTE_DEBUG === "1";
887
891
  function sleep(ms) {
888
892
  return new Promise((resolve) => setTimeout(resolve, ms));
@@ -918,6 +922,11 @@ function isPageStackProtocolTimeout(error) {
918
922
  function isCallWxMethodProtocolTimeout(error) {
919
923
  return error instanceof Error && "code" in error && error.code === "DEVTOOLS_PROTOCOL_TIMEOUT" && "method" in error && error.method === "App.callWxMethod";
920
924
  }
925
+ function isCaptureScreenshotRecoverableError(error) {
926
+ if (!(error instanceof Error)) return false;
927
+ if ("code" in error && error.code === "DEVTOOLS_PROTOCOL_TIMEOUT" && "method" in error && error.method === "App.captureScreenshot") return true;
928
+ return error.message.includes("fail to capture screenshot") || error.message.includes("App.captureScreenshot");
929
+ }
921
930
  function isRouteContextProbeError(error) {
922
931
  return isCurrentPageProtocolTimeout(error) || isPageStackProtocolTimeout(error);
923
932
  }
@@ -1126,9 +1135,20 @@ var MiniProgram = class extends EventEmitter {
1126
1135
  throw lastError instanceof Error ? lastError : /* @__PURE__ */ new Error(`Timed out waiting App domain readiness after ${timeout}ms`);
1127
1136
  }
1128
1137
  async screenshot(options = {}) {
1129
- const { data } = await this.send("App.captureScreenshot");
1130
- if (!options.path) return data;
1131
- await fs.writeFile(options.path, data, "base64");
1138
+ const sendOptions = options.timeout ? { timeout: options.timeout } : void 0;
1139
+ let lastError;
1140
+ let data;
1141
+ for (let attempt = 1; attempt <= SCREENSHOT_RETRIES; attempt += 1) try {
1142
+ data = (await this.send("App.captureScreenshot", {}, sendOptions)).data;
1143
+ if (!options.path) return data;
1144
+ await fs.writeFile(options.path, data, "base64");
1145
+ return;
1146
+ } catch (error) {
1147
+ lastError = error;
1148
+ if (!isCaptureScreenshotRecoverableError(error) || attempt === SCREENSHOT_RETRIES) throw error;
1149
+ await sleep(SCREENSHOT_RETRY_DELAY);
1150
+ }
1151
+ throw lastError;
1132
1152
  }
1133
1153
  async testAccounts() {
1134
1154
  return (await this.send("Tool.getTestAccounts")).accounts;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@weapp-vite/miniprogram-automator",
3
3
  "type": "module",
4
- "version": "1.2.2",
4
+ "version": "1.2.4",
5
5
  "description": "完全兼容微信 miniprogram-automator 的现代化替代实现",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -41,9 +41,9 @@
41
41
  "node": "^20.19.0 || >=22.12.0"
42
42
  },
43
43
  "dependencies": {
44
- "obug": "^2.1.1",
44
+ "obug": "^2.1.3",
45
45
  "ws": "^8.21.0",
46
- "@weapp-vite/qr": "1.1.0"
46
+ "@weapp-vite/qr": "1.1.1"
47
47
  },
48
48
  "publishConfig": {
49
49
  "access": "public",
@@ -51,7 +51,7 @@
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/ws": "^8.18.1",
54
- "sharp": "^0.34.5"
54
+ "sharp": "^0.35.1"
55
55
  },
56
56
  "scripts": {
57
57
  "dev": "tsdown -w --sourcemap",