@mobilewright/inspector 0.0.60 → 0.0.61

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.
Files changed (42) hide show
  1. package/dist/index.d.ts +4 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +42 -8
  4. package/dist/index.js.map +1 -1
  5. package/dist/lib/device-manager.d.ts +24 -9
  6. package/dist/lib/device-manager.d.ts.map +1 -1
  7. package/dist/lib/device-manager.js +95 -14
  8. package/dist/lib/device-manager.js.map +1 -1
  9. package/dist/lib/inspect-screen.d.ts +47 -0
  10. package/dist/lib/inspect-screen.d.ts.map +1 -0
  11. package/dist/lib/inspect-screen.js +104 -0
  12. package/dist/lib/inspect-screen.js.map +1 -0
  13. package/dist/lib/locator-derivation.d.ts +15 -2
  14. package/dist/lib/locator-derivation.d.ts.map +1 -1
  15. package/dist/lib/locator-derivation.js +21 -6
  16. package/dist/lib/locator-derivation.js.map +1 -1
  17. package/dist/lib/timeout.d.ts +3 -0
  18. package/dist/lib/timeout.d.ts.map +1 -0
  19. package/dist/lib/timeout.js +9 -0
  20. package/dist/lib/timeout.js.map +1 -0
  21. package/dist/routes/device-actions.d.ts +7 -0
  22. package/dist/routes/device-actions.d.ts.map +1 -0
  23. package/dist/routes/device-actions.js +79 -0
  24. package/dist/routes/device-actions.js.map +1 -0
  25. package/dist/routes/devices.d.ts +1 -1
  26. package/dist/routes/devices.d.ts.map +1 -1
  27. package/dist/routes/devices.js +10 -11
  28. package/dist/routes/devices.js.map +1 -1
  29. package/dist/routes/inspect.d.ts.map +1 -1
  30. package/dist/routes/inspect.js +22 -92
  31. package/dist/routes/inspect.js.map +1 -1
  32. package/package.json +3 -3
  33. package/public/codegen.html +119 -0
  34. package/public/css/app.css +250 -0
  35. package/public/fonts/codicon-LICENSE.txt +21 -0
  36. package/public/fonts/codicon.ttf +0 -0
  37. package/public/index.html +3 -2
  38. package/public/js/app.js +203 -55
  39. package/public/js/codegen.js +301 -0
  40. package/public/js/inspect.js +7 -0
  41. package/public/js/view-tree.js +182 -0
  42. package/public/logo.png +0 -0
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { type MobilewrightLauncher } from './lib/device-manager.js';
1
+ import express from 'express';
2
+ import { DeviceManager, type MobilewrightLauncher } from './lib/device-manager.js';
2
3
  export type { MobilewrightLauncher };
3
4
  /** Options passed to {@link start}. */
4
5
  export interface InspectorOptions {
@@ -16,6 +17,8 @@ export interface InspectorServer {
16
17
  /** Gracefully close the device connection and stop the HTTP server. */
17
18
  close: () => Promise<void>;
18
19
  }
20
+ /** The Inspector's Express app, without listening; split out so tests can drive it directly. */
21
+ export declare function createApp(deviceManager: DeviceManager): express.Express;
19
22
  /**
20
23
  * Start the Mobilewright Inspector HTTP server.
21
24
  * Pass the ios and android launcher objects from mobilewright so the inspector
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAiB,KAAK,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAInF,YAAY,EAAE,oBAAoB,EAAE,CAAC;AAErC,uCAAuC;AACvC,MAAM,WAAW,gBAAgB;IAC/B,sCAAsC;IACtC,GAAG,EAAE,oBAAoB,CAAC;IAC1B,0CAA0C;IAC1C,OAAO,EAAE,oBAAoB,CAAC;IAC9B,gDAAgD;IAChD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,oFAAoF;AACpF,MAAM,WAAW,eAAe;IAC9B,2EAA2E;IAC3E,GAAG,EAAE,MAAM,CAAC;IACZ,uEAAuE;IACvE,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAED;;;;GAIG;AACH,wBAAsB,KAAK,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,IAAW,EAAE,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAwCrG"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAK9B,OAAO,EAAE,aAAa,EAAE,KAAK,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAKnF,YAAY,EAAE,oBAAoB,EAAE,CAAC;AAErC,uCAAuC;AACvC,MAAM,WAAW,gBAAgB;IAC/B,sCAAsC;IACtC,GAAG,EAAE,oBAAoB,CAAC;IAC1B,0CAA0C;IAC1C,OAAO,EAAE,oBAAoB,CAAC;IAC9B,gDAAgD;IAChD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,oFAAoF;AACpF,MAAM,WAAW,eAAe;IAC9B,2EAA2E;IAC3E,GAAG,EAAE,MAAM,CAAC;IACZ,uEAAuE;IACvE,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAiCD,gGAAgG;AAChG,wBAAgB,SAAS,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAiBvE;AAED;;;;GAIG;AACH,wBAAsB,KAAK,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,IAAW,EAAE,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAyBrG"}
package/dist/index.js CHANGED
@@ -5,25 +5,59 @@ import http from 'node:http';
5
5
  import { DeviceManager } from './lib/device-manager.js';
6
6
  import { createDevicesRouter } from './routes/devices.js';
7
7
  import { createInspectRouter } from './routes/inspect.js';
8
+ import { createDeviceActionsRouter } from './routes/device-actions.js';
9
+ const PUBLIC_DIR = join(dirname(fileURLToPath(import.meta.url)), '..', 'public');
10
+ /** Hostnames that address this machine. */
11
+ const LOOPBACK_HOSTNAMES = new Set(['127.0.0.1', 'localhost', '[::1]']);
8
12
  /**
9
- * Start the Mobilewright Inspector HTTP server.
10
- * Pass the ios and android launcher objects from mobilewright so the inspector
11
- * can list and connect to devices without a circular dependency.
13
+ * Only answer requests addressed to a loopback hostname. With DNS rebinding, a page on another site
14
+ * can point its own hostname at 127.0.0.1 and then call this server as a same-origin page, which
15
+ * the JSON-only rule below does not stop; its requests still carry that foreign Host header.
12
16
  */
13
- export async function start({ ios, android, port = 4621 }) {
14
- const publicDir = join(dirname(fileURLToPath(import.meta.url)), '..', 'public');
17
+ const rejectNonLoopbackHosts = (req, res, next) => {
18
+ if (!LOOPBACK_HOSTNAMES.has(req.hostname)) {
19
+ res.status(403).json({ error: 'The Inspector only answers requests addressed to localhost' });
20
+ return;
21
+ }
22
+ next();
23
+ };
24
+ /**
25
+ * Every POST must be JSON. A page on another site can send a "simple" POST (form, text/plain or no
26
+ * body) straight to localhost without a CORS preflight; requiring JSON forces the preflight, which
27
+ * this server never answers, so only the Inspector's own pages can drive the device.
28
+ */
29
+ const rejectNonJsonPosts = (req, res, next) => {
30
+ if (req.method === 'POST' && !req.is('application/json')) {
31
+ res.status(415).json({ error: 'POST requests must send a JSON body' });
32
+ return;
33
+ }
34
+ next();
35
+ };
36
+ /** The Inspector's Express app, without listening; split out so tests can drive it directly. */
37
+ export function createApp(deviceManager) {
15
38
  const app = express();
39
+ app.use(rejectNonLoopbackHosts);
40
+ app.use(rejectNonJsonPosts);
16
41
  app.use(express.json());
17
- app.use(express.static(publicDir));
42
+ app.use(express.static(PUBLIC_DIR, { extensions: ['html'] }));
18
43
  app.get('/health', (_req, res) => res.json({ ok: true }));
19
- const deviceManager = new DeviceManager({ ios, android });
20
44
  app.use('/api/devices', createDevicesRouter(deviceManager));
21
45
  app.use('/api', createInspectRouter(deviceManager));
46
+ app.use('/api', createDeviceActionsRouter(deviceManager));
22
47
  // 4-argument signature is required by Express to treat this as an error handler
23
48
  app.use((err, _req, res, _next) => {
24
49
  res.status(500).json({ error: err.message });
25
50
  });
26
- const server = http.createServer(app);
51
+ return app;
52
+ }
53
+ /**
54
+ * Start the Mobilewright Inspector HTTP server.
55
+ * Pass the ios and android launcher objects from mobilewright so the inspector
56
+ * can list and connect to devices without a circular dependency.
57
+ */
58
+ export async function start({ ios, android, port = 4621 }) {
59
+ const deviceManager = new DeviceManager({ ios, android });
60
+ const server = http.createServer(createApp(deviceManager));
27
61
  await new Promise((resolve, reject) => {
28
62
  server.once('error', reject);
29
63
  server.listen(port, '127.0.0.1', () => resolve());
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,aAAa,EAA6B,MAAM,yBAAyB,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAsB1D;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,KAAK,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,GAAG,IAAI,EAAoB;IACzE,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;IAEhF,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC;IACtB,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;IACxB,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;IACnC,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAE1D,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC,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EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;SACtC,CAAC,CAAC;IACL,CAAC;IAED,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;AACxB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { Device } from '@mobilewright/core';
2
- import type { DeviceInfo } from '@mobilewright/protocol';
2
+ import type { DeviceInfo, ScreenSize } from '@mobilewright/protocol';
3
3
  /** Platform launcher injected from mobilewright to avoid a circular dependency. */
4
4
  export interface MobilewrightLauncher {
5
5
  /** List all connected/booted devices for this platform. */
@@ -12,7 +12,7 @@ export interface MobilewrightLauncher {
12
12
  }): Promise<Device>;
13
13
  }
14
14
  /** Discriminated union of error codes thrown by DeviceManager. */
15
- export type DeviceErrorCode = 'blocked' | 'in_progress' | 'not_found' | 'connect_failed';
15
+ export type DeviceErrorCode = 'in_progress' | 'not_found' | 'connect_failed';
16
16
  /** Structured error thrown by DeviceManager for expected failure modes. */
17
17
  export declare class DeviceError extends Error {
18
18
  /** Machine-readable error code indicating the failure reason. */
@@ -24,6 +24,13 @@ export declare class DeviceError extends Error {
24
24
  export type TaggedDeviceInfo = DeviceInfo & {
25
25
  platform: 'ios' | 'android';
26
26
  };
27
+ /** Options for {@link DeviceManager}. */
28
+ export interface DeviceManagerOptions {
29
+ ios: MobilewrightLauncher;
30
+ android: MobilewrightLauncher;
31
+ /** How long a screen size call may take before it counts as failed and is asked again. */
32
+ screenSizeTimeoutMs?: number;
33
+ }
27
34
  /** Minimal device identity record held by DeviceManager while a device is active. */
28
35
  export type DeviceInfoRecord = {
29
36
  id: string;
@@ -36,10 +43,7 @@ export type DeviceInfoRecord = {
36
43
  export declare class DeviceManager {
37
44
  #private;
38
45
  /** @param ios iOS launcher from mobilewright. @param android Android launcher from mobilewright. */
39
- constructor({ ios, android }: {
40
- ios: MobilewrightLauncher;
41
- android: MobilewrightLauncher;
42
- });
46
+ constructor({ ios, android, screenSizeTimeoutMs }: DeviceManagerOptions);
43
47
  /**
44
48
  * List all connected/booted devices across both platforms.
45
49
  * Each platform is queried independently so a failure on one does not hide the other.
@@ -47,8 +51,11 @@ export declare class DeviceManager {
47
51
  listDevices(): Promise<TaggedDeviceInfo[]>;
48
52
  /**
49
53
  * Connect to a device, closing any previous connection first.
50
- * Throws DeviceError if an inspect is in flight, a select is already in progress,
51
- * or the previous device cannot be cleanly disconnected.
54
+ * Waits for in-flight inspects and device actions to finish (codegen refreshes back to back, so
55
+ * an inspect is nearly always running) and refuses new ones until the switch is done, so nothing
56
+ * uses a device while it is being closed.
57
+ * Throws DeviceError if a select is already in progress or the previous device cannot be
58
+ * cleanly disconnected.
52
59
  */
53
60
  select(deviceId: string, platform: 'ios' | 'android'): Promise<Device>;
54
61
  /**
@@ -56,13 +63,21 @@ export declare class DeviceManager {
56
63
  * Returns false if an inspect is already in flight or a device switch is in progress.
57
64
  */
58
65
  beginInspect(): boolean;
59
- /** Clear the inspect-in-flight flag set by beginInspect(). */
66
+ /** Clear the inspect-in-flight flag set by beginInspect(), releasing a waiting select(). */
60
67
  endInspect(): void;
68
+ /**
69
+ * Run a device action (tap, button press, ...) on the active device. A device switch waits for it
70
+ * before closing the device. Rejects with DeviceError 'not_found' without a device, and
71
+ * 'in_progress' while a switch is underway.
72
+ */
73
+ withDevice<T>(run: (device: Device) => Promise<T>): Promise<T>;
61
74
  /**
62
75
  * Close the active device connection. Safe to call with no active device.
63
76
  * Throws if the underlying driver close fails; state is only cleared on success.
64
77
  */
65
78
  close(): Promise<void>;
79
+ /** The active device's screen size, asked once per connection; a failed ask is retried next call. */
80
+ screenSize(): Promise<ScreenSize>;
66
81
  /** The currently connected device, or null if none selected. */
67
82
  get device(): Device | null;
68
83
  /** Id and platform of the currently connected device, or null if none selected. */
@@ -1 +1 @@
1
- {"version":3,"file":"device-manager.d.ts","sourceRoot":"","sources":["../../src/lib/device-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAA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AoB,CAAC;IAC1B,OAAO,EAAE,oBAAoB,CAAC;IAC9B,0FAA0F;IAC1F,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED,qFAAqF;AACrF,MAAM,MAAM,gBAAgB,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,KAAK,GAAG,SAAS,CAAA;CAAE,CAAC;AAE3E;;;GAGG;AACH,qBAAa,aAAa;;IA2BxB,oGAAoG;gBACxF,EAAE,GAAG,EAAE,OAAO,EAAE,mBAAoD,EAAE,EAAE,oBAAoB;IAMxG;;;OAGG;IACG,WAAW,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;IAahD;;;;;;;OAOG;IACG,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IAyC5E;;;OAGG;IACH,YAAY,IAAI,OAAO;IASvB,4FAA4F;IAC5F,UAAU,IAAI,IAAI;IAQlB;;;;OAIG;IACG,UAAU,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAgCpE;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAc5B,qGAAqG;IACrG,UAAU,IAAI,OAAO,CAAC,UAAU,CAAC;IAyBjC,gEAAgE;IAChE,IAAI,MAAM,IAAI,MAAM,GAAG,IAAI,CAA+B;IAE1D,mFAAmF;IACnF,IAAI,UAAU,IAAI,gBAAgB,GAAG,IAAI,CAAmC;CAC7E"}
@@ -1,4 +1,6 @@
1
1
  import { logger } from './logger.js';
2
+ import { timeoutAfter } from './timeout.js';
3
+ const DEFAULT_SCREEN_SIZE_TIMEOUT_MS = 10_000;
2
4
  /** Structured error thrown by DeviceManager for expected failure modes. */
3
5
  export class DeviceError extends Error {
4
6
  /** @param message Human-readable description. @param code Machine-readable failure reason. */
@@ -21,16 +23,28 @@ export class DeviceManager {
21
23
  #activeDevice = null;
22
24
  /** Identity of the currently connected device, or null when no device is selected. */
23
25
  #activeDeviceInfo = null;
24
- /** True while an inspect operation is in progress; blocks concurrent select(). */
26
+ /** True while an inspect is in progress; only one runs at a time. */
25
27
  #inspectInFlight = false;
28
+ /** Inspects and device actions currently using the active device; select() waits for them. */
29
+ #operationsInFlight = 0;
30
+ /** Resolves when #operationsInFlight drops to 0; null when nothing is running. */
31
+ #operationsDone = null;
32
+ #resolveOperationsDone = null;
26
33
  /** True while a select() call is awaiting launcher.launch(); blocks concurrent select(). */
27
34
  #selecting = false;
35
+ /**
36
+ * The active device's screen size, fetched once per connection: it never changes while connected,
37
+ * yet asking costs ~250ms. ponytail: stale after the device rotates; key by orientation if needed.
38
+ */
39
+ #screenSize = null;
40
+ #screenSizeTimeoutMs;
28
41
  /** True after close() is called; prevents new connections after shutdown. */
29
42
  #closed = false;
30
43
  /** @param ios iOS launcher from mobilewright. @param android Android launcher from mobilewright. */
31
- constructor({ ios, android }) {
44
+ constructor({ ios, android, screenSizeTimeoutMs = DEFAULT_SCREEN_SIZE_TIMEOUT_MS }) {
32
45
  this.#ios = ios;
33
46
  this.#android = android;
47
+ this.#screenSizeTimeoutMs = screenSizeTimeoutMs;
34
48
  }
35
49
  /**
36
50
  * List all connected/booted devices across both platforms.
@@ -52,24 +66,27 @@ export class DeviceManager {
52
66
  }
53
67
  /**
54
68
  * Connect to a device, closing any previous connection first.
55
- * Throws DeviceError if an inspect is in flight, a select is already in progress,
56
- * or the previous device cannot be cleanly disconnected.
69
+ * Waits for in-flight inspects and device actions to finish (codegen refreshes back to back, so
70
+ * an inspect is nearly always running) and refuses new ones until the switch is done, so nothing
71
+ * uses a device while it is being closed.
72
+ * Throws DeviceError if a select is already in progress or the previous device cannot be
73
+ * cleanly disconnected.
57
74
  */
58
75
  async select(deviceId, platform) {
59
- if (this.#closed)
76
+ if (this.#closed) {
60
77
  throw new DeviceError('DeviceManager is closed', 'connect_failed');
61
- if (this.#inspectInFlight)
62
- throw new DeviceError('Device switch blocked: inspect in progress', 'blocked');
63
- if (this.#selecting)
78
+ }
79
+ if (this.#selecting) {
64
80
  throw new DeviceError('Device switch already in progress', 'in_progress');
81
+ }
65
82
  this.#selecting = true;
66
83
  try {
84
+ await this.#operationsDone;
67
85
  if (this.#activeDevice) {
68
86
  logger.info(`Closing previous device ${this.#activeDeviceInfo?.id}`);
69
87
  try {
70
88
  await this.#activeDevice.close();
71
- this.#activeDevice = null;
72
- this.#activeDeviceInfo = null;
89
+ this.#forgetActiveDevice();
73
90
  }
74
91
  catch (err) {
75
92
  logger.error(`Failed to close device ${this.#activeDeviceInfo?.id}: ${err.message}`);
@@ -106,14 +123,55 @@ export class DeviceManager {
106
123
  * Returns false if an inspect is already in flight or a device switch is in progress.
107
124
  */
108
125
  beginInspect() {
109
- if (this.#inspectInFlight || this.#selecting)
126
+ if (this.#inspectInFlight || this.#selecting) {
110
127
  return false;
128
+ }
111
129
  this.#inspectInFlight = true;
130
+ this.#startOperation();
112
131
  return true;
113
132
  }
114
- /** Clear the inspect-in-flight flag set by beginInspect(). */
133
+ /** Clear the inspect-in-flight flag set by beginInspect(), releasing a waiting select(). */
115
134
  endInspect() {
135
+ if (!this.#inspectInFlight) {
136
+ return;
137
+ }
116
138
  this.#inspectInFlight = false;
139
+ this.#endOperation();
140
+ }
141
+ /**
142
+ * Run a device action (tap, button press, ...) on the active device. A device switch waits for it
143
+ * before closing the device. Rejects with DeviceError 'not_found' without a device, and
144
+ * 'in_progress' while a switch is underway.
145
+ */
146
+ async withDevice(run) {
147
+ if (this.#selecting) {
148
+ throw new DeviceError('Device switch in progress', 'in_progress');
149
+ }
150
+ const device = this.#activeDevice;
151
+ if (!device) {
152
+ throw new DeviceError('No device selected', 'not_found');
153
+ }
154
+ this.#startOperation();
155
+ try {
156
+ return await run(device);
157
+ }
158
+ finally {
159
+ this.#endOperation();
160
+ }
161
+ }
162
+ #startOperation() {
163
+ this.#operationsInFlight++;
164
+ if (!this.#operationsDone) {
165
+ this.#operationsDone = new Promise(resolve => { this.#resolveOperationsDone = resolve; });
166
+ }
167
+ }
168
+ #endOperation() {
169
+ this.#operationsInFlight--;
170
+ if (this.#operationsInFlight === 0) {
171
+ this.#resolveOperationsDone?.();
172
+ this.#resolveOperationsDone = null;
173
+ this.#operationsDone = null;
174
+ }
117
175
  }
118
176
  /**
119
177
  * Close the active device connection. Safe to call with no active device.
@@ -125,8 +183,7 @@ export class DeviceManager {
125
183
  logger.info(`Closing device ${this.#activeDeviceInfo?.id}`);
126
184
  try {
127
185
  await this.#activeDevice.close();
128
- this.#activeDevice = null;
129
- this.#activeDeviceInfo = null;
186
+ this.#forgetActiveDevice();
130
187
  }
131
188
  catch (err) {
132
189
  logger.error(`Failed to close device ${this.#activeDeviceInfo?.id}: ${err.message}`);
@@ -134,6 +191,30 @@ export class DeviceManager {
134
191
  }
135
192
  }
136
193
  }
194
+ /** The active device's screen size, asked once per connection; a failed ask is retried next call. */
195
+ screenSize() {
196
+ const device = this.#activeDevice;
197
+ if (!device) {
198
+ return Promise.reject(new DeviceError('No device selected', 'not_found'));
199
+ }
200
+ if (!this.#screenSize) {
201
+ // The timeout is on the cached promise itself: a call that hangs must count as failed so the
202
+ // next caller asks again, instead of every caller waiting on it forever.
203
+ const size = timeoutAfter(device.screenSize(), this.#screenSizeTimeoutMs);
204
+ this.#screenSize = size;
205
+ size.catch(() => {
206
+ if (this.#screenSize === size) {
207
+ this.#screenSize = null;
208
+ }
209
+ });
210
+ }
211
+ return this.#screenSize;
212
+ }
213
+ #forgetActiveDevice() {
214
+ this.#activeDevice = null;
215
+ this.#activeDeviceInfo = null;
216
+ this.#screenSize = null;
217
+ }
137
218
  /** The currently connected device, or null if none selected. */
138
219
  get device() { return this.#activeDevice; }
139
220
  /** Id and platform of the currently connected device, or null if none selected. */
@@ -1 +1 @@
1
- {"version":3,"file":"device-manager.js","sourceRoot":"","sources":["../../src/lib/device-man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
3
+ import { type ElementEntry } from './locator-derivation.js';
4
+ /** An element as the Inspector page receives it. */
5
+ export type ElementJson = ReturnType<typeof toElementJson>;
6
+ /** One captured moment of the device screen. */
7
+ export interface InspectedScreen {
8
+ screenshot: Buffer;
9
+ screen: {
10
+ width: number;
11
+ height: number;
12
+ scale: number;
13
+ };
14
+ elements: ElementJson[];
15
+ /** SHA-1 over screenshot, screen and elements: equal etags mean an identical capture. */
16
+ etag: string;
17
+ }
18
+ /** JPEG at 60 is ~4x smaller than PNG for the same capture time. */
19
+ export declare const SCREENSHOT_MIME_TYPE = "image/jpeg";
20
+ /**
21
+ * Capture the screen at `scale` (0 < scale <= 1). `screenSize` is injected so the caller can
22
+ * serve it from a per-connection cache.
23
+ */
24
+ export declare function inspectScreen(device: Device, scale: number, screenSize: () => Promise<ScreenSize>): Promise<InspectedScreen>;
25
+ declare function toElementJson({ node, locator, locators, depth }: ElementEntry, index: number, tree: ViewNode[]): {
26
+ index: number;
27
+ depth: number;
28
+ type: string;
29
+ label: string | null;
30
+ text: string | null;
31
+ bounds: import("@mobilewright/protocol").Bounds;
32
+ isVisible: boolean;
33
+ identifier: string | null;
34
+ resourceId: string | null;
35
+ placeholder: string | null;
36
+ value: string | null;
37
+ isEnabled: boolean;
38
+ isSelected: boolean | null;
39
+ isFocused: boolean | null;
40
+ isChecked: boolean | null;
41
+ raw: Record<string, unknown> | null;
42
+ locator: import("./locator-derivation.js").Locator | null;
43
+ locators: import("./locator-derivation.js").Locator[];
44
+ match: import("./locator-derivation.js").MatchPosition | null;
45
+ };
46
+ export {};
47
+ //# sourceMappingURL=inspect-screen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inspect-screen.d.ts","sourceRoot":"","sources":["../../src/lib/inspect-screen.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAA2C,KAAK,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAIrG,oDAAoD;AACpD,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AAE3D,gDAAgD;AAChD,MAAM,WAAW,eAAe;IAC9B,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACzD,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,yFAAyF;IACzF,IAAI,EAAE,MAAM,CAAC;CACd;AAED,oEAAoE;AACpE,eAAO,MAAM,oBAAoB,eAAe,CAAC;AAUjD;;;GAGG;AACH,wBAAsB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,CASlI;AAED,iBAAS,aAAa,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;EAsBvG"}
@@ -0,0 +1,104 @@
1
+ // Captures one moment of the device screen for the Inspector and codegen: screenshot, element
2
+ // list with derived locators, and screen size, plus an etag that changes whenever any of them does.
3
+ import { createHash } from 'node:crypto';
4
+ import { deriveElementList, locatorMatchPosition } from './locator-derivation.js';
5
+ import { logger } from './logger.js';
6
+ import { timeoutAfter } from './timeout.js';
7
+ /** JPEG at 60 is ~4x smaller than PNG for the same capture time. */
8
+ export const SCREENSHOT_MIME_TYPE = 'image/jpeg';
9
+ const SCREENSHOT_FORMAT = { format: 'jpeg', quality: 60 };
10
+ const MAX_RETRIES = 3;
11
+ const RETRY_DELAY_MS = 1500;
12
+ const OP_TIMEOUT_MS = 10_000;
13
+ /**
14
+ * Capture the screen at `scale` (0 < scale <= 1). `screenSize` is injected so the caller can
15
+ * serve it from a per-connection cache.
16
+ */
17
+ export async function inspectScreen(device, scale, screenSize) {
18
+ const { screenshot, tree, size } = await captureWithRetry({
19
+ screenshot: () => device.screen.screenshot({ ...SCREENSHOT_FORMAT, scale }),
20
+ tree: () => device.screen.viewTree(),
21
+ size: screenSize,
22
+ });
23
+ const screen = { width: size.width, height: size.height, scale: size.scale };
24
+ const elements = deriveElementList(tree).map((entry, index) => toElementJson(entry, index, tree));
25
+ return { screenshot, screen, elements, etag: etagOf(screenshot, screen, elements) };
26
+ }
27
+ function toElementJson({ node, locator, locators, depth }, index, tree) {
28
+ return {
29
+ index,
30
+ depth,
31
+ type: node.type,
32
+ label: node.label ?? null,
33
+ text: node.text ?? null,
34
+ bounds: node.bounds,
35
+ isVisible: node.isVisible,
36
+ identifier: node.identifier ?? null,
37
+ resourceId: node.resourceId ?? null,
38
+ placeholder: node.placeholder ?? null,
39
+ value: node.value ?? null,
40
+ isEnabled: node.isEnabled ?? true,
41
+ isSelected: node.isSelected ?? null,
42
+ isFocused: node.isFocused ?? null,
43
+ isChecked: node.isChecked ?? null,
44
+ raw: node.raw ?? null,
45
+ locator,
46
+ locators,
47
+ match: locator ? locatorMatchPosition(tree, node, locator) : null,
48
+ };
49
+ }
50
+ function etagOf(screenshot, screen, elements) {
51
+ return createHash('sha1')
52
+ .update(screenshot)
53
+ .update(JSON.stringify(screen))
54
+ .update(JSON.stringify(elements))
55
+ .digest('hex');
56
+ }
57
+ /**
58
+ * Run the three captures, retrying up to MAX_RETRIES.
59
+ *
60
+ * Strategy: first attempt runs all 3 in parallel for speed. Retries
61
+ * run only the failed ops sequentially (1 at a time) so that abandoned
62
+ * RPCs from timed-out attempts never stack up more than 2 concurrent
63
+ * mobilecli worker slots per retry cycle.
64
+ */
65
+ async function captureWithRetry(captures) {
66
+ const keys = Object.keys(captures);
67
+ const results = {};
68
+ const isDone = (key) => key in results;
69
+ const run = (key) => timeoutAfter(captures[key](), OP_TIMEOUT_MS);
70
+ for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
71
+ const pending = keys.filter(key => !isDone(key));
72
+ if (pending.length === 0) {
73
+ break;
74
+ }
75
+ if (attempt === 0) {
76
+ const settled = await Promise.allSettled(pending.map(run));
77
+ settled.forEach((result, i) => {
78
+ if (result.status === 'fulfilled') {
79
+ Object.assign(results, { [pending[i]]: result.value });
80
+ }
81
+ });
82
+ }
83
+ else {
84
+ for (const key of pending) {
85
+ try {
86
+ Object.assign(results, { [key]: await run(key) });
87
+ }
88
+ catch (err) {
89
+ logger.warn(`Inspect ${key} attempt ${attempt + 1}/${MAX_RETRIES} failed: ${err.message}`);
90
+ }
91
+ }
92
+ }
93
+ const isLastAttempt = attempt === MAX_RETRIES - 1;
94
+ if (!isLastAttempt && keys.some(key => !isDone(key))) {
95
+ await new Promise(resolve => setTimeout(resolve, RETRY_DELAY_MS));
96
+ }
97
+ }
98
+ const missing = keys.filter(key => !isDone(key));
99
+ if (missing.length > 0) {
100
+ throw new Error(`Inspect failed: ${missing.join(', ')} did not complete`);
101
+ }
102
+ return results;
103
+ }
104
+ //# sourceMappingURL=inspect-screen.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inspect-screen.js","sourceRoot":"","sources":["../../src/lib/inspect-screen.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,oGAAoG;AAEpG,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAqB,MAAM,yBAAyB,CAAC;AACrG,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAc5C,oEAAoE;AACpE,MAAM,CAAC,MAAM,oBAAoB,GAAG,YAAY,CAAC;AACjD,MAAM,iBAAiB,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO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CAAC;QACH,CAAC;QAED,MAAM,aAAa,GAAG,OAAO,KAAK,WAAW,GAAG,CAAC,CAAC;QAClD,IAAI,CAAC,aAAa,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YACrD,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAC;QACpE,CAAC;IACH,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IACjD,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,mBAAmB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;IAC5E,CAAC;IACD,OAAO,OAAkB,CAAC;AAC5B,CAAC"}
@@ -14,10 +14,12 @@ export type Locator = {
14
14
  kind: 'text';
15
15
  value: string;
16
16
  };
17
- interface ElementEntry {
17
+ export interface ElementEntry {
18
18
  node: ViewNode;
19
19
  locator: Locator | null;
20
20
  locators: Locator[];
21
+ /** Nesting level in the view tree; roots are 0. With the depth-first order this rebuilds the tree. */
22
+ depth: number;
21
23
  }
22
24
  /**
23
25
  * Derive all matching mobilewright locators for a single ViewNode.
@@ -32,5 +34,16 @@ export declare function deriveLocator(node: ViewNode): Locator | null;
32
34
  * Nodes with no locatable field are included with locators: [].
33
35
  */
34
36
  export declare function deriveElementList(roots: ViewNode[]): ElementEntry[];
35
- export {};
37
+ /** Where a node sits among every node its locator matches. */
38
+ export interface MatchPosition {
39
+ index: number;
40
+ count: number;
41
+ }
42
+ /**
43
+ * Position of `node` among all matches of `locator`, computed with core's own query
44
+ * engine, so `index` is exactly what `.nth(index)` resolves to when the test runs.
45
+ * Returns null when the locator does not match the node at all.
46
+ * ponytail: one full-tree query per element, O(n²) per refresh; index the tree if screens get huge.
47
+ */
48
+ export declare function locatorMatchPosition(roots: ViewNode[], node: ViewNode, locator: Locator): MatchPosition | null;
36
49
  //# sourceMappingURL=locator-derivation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"locator-derivation.d.ts","sourceRoot":"","sources":["../../src/lib/locator-derivation.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAavD,gFAAgF;AAChF,MAAM,MAAM,OAAO,GACf;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAG,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAA;CAAE,GAC3D;IAAE,IAAI,EAAE,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAG,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEtC,UAAU,YAAY;IACpB,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB;AAyBD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,EAAE,CAkBxD;AAED,+FAA+F;AAC/F,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,GAAG,OAAO,GAAG,IAAI,CAE5D;AAoDD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,QAAQ,EAAE,GAAG,YAAY,EAAE,CAanE"}
1
+ {"version":3,"file":"locator-derivation.d.ts","sourceRoot":"","sources":["../../src/lib/locator-derivation.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB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