@lynx-js/devtool-connector 0.17.0 → 0.18.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # @lynx-js/devtool-connector
2
2
 
3
+ ## 0.18.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Include transport and request context when a connection ends before a response.
8
+ - Add sandbox apps open -S/--restart to stop the target app before launching its page through the shared Transport restart option.
9
+ - Use the open command's deadline while waiting for the page SessionList, while keeping the 10-second default for direct library calls.
10
+ - Preserve device transport error names, codes and messages in daemon WebSocket close reasons.
11
+ - Allow HDT client discovery three seconds to complete its handshake and fresh ClientList exchange.
12
+
13
+ ## 0.18.0
14
+
15
+ ### Minor Changes
16
+
17
+ - Add an optional `schema` to `Connector.openApp`, including daemon forwarding. Android opens the schema directly in the requested app, with shell-safe URL handling, instead of launching its default activity. Other transports ignore the option unless supported.
18
+
3
19
  ## 0.17.0
4
20
 
5
21
  ### Patch Changes
package/dist/2.js CHANGED
@@ -1659,7 +1659,7 @@ const DAEMON_SHUTDOWN_PATH = `${DAEMON_WS_PATH}/shutdown`;
1659
1659
  const DAEMON_INSPECTOR_PATH = `${DAEMON_WS_PATH}/inspector`;
1660
1660
  const DAEMON_COMMAND_PATH_PREFIX = "/command/";
1661
1661
  var package_namespaceObject = {
1662
- rE: "0.17.0"
1662
+ rE: "0.18.1"
1663
1663
  };
1664
1664
  const CONNECTOR_VERSION = package_namespaceObject.rE;
1665
1665
  const node_modules_semver = __webpack_require__("../../../node_modules/.pnpm/semver@7.8.5/node_modules/semver/index.js");
package/dist/a.js CHANGED
@@ -80,6 +80,15 @@ const clientSetupSwitches = [
80
80
  function hasClientList(transport) {
81
81
  return "function" == typeof transport.listClients;
82
82
  }
83
+ function describeRequest(input) {
84
+ if ("object" != typeof input || null === input) return "request";
85
+ const message = input;
86
+ if ("string" == typeof message["method"]) return `method ${message["method"]}`;
87
+ if ("string" != typeof message["event"]) return "request";
88
+ const data = "object" == typeof message["data"] && null !== message["data"] ? message["data"] : void 0;
89
+ if ("string" == typeof data?.["type"]) return `${message["event"]} ${data["type"]}`;
90
+ return `${message["event"]} event`;
91
+ }
83
92
  function isNonEmptyListSessionResponse(response) {
84
93
  return isListSessionResponse(response) && response.data.data.length > 0;
85
94
  }
@@ -202,7 +211,7 @@ class Connector {
202
211
  ]
203
212
  });
204
213
  }
205
- async openPage(clientId, url) {
214
+ async openPage(clientId, url, signal) {
206
215
  return await this.#sendMessage(clientId, {
207
216
  event: "Customized",
208
217
  data: {
@@ -219,7 +228,7 @@ class Connector {
219
228
  output: [
220
229
  new FilterTransformStream(isNonEmptyListSessionResponse)
221
230
  ]
222
- });
231
+ }, signal);
223
232
  }
224
233
  async sendCDPMessage(clientId, sessionId, method, params, isMainThread = false) {
225
234
  const id = nextRequestId();
@@ -417,17 +426,16 @@ class Connector {
417
426
  async #sendMessage(clientId, input, pipeline = {
418
427
  input: [],
419
428
  output: []
420
- }) {
429
+ }, signal) {
421
430
  const { deviceId, port } = this.#resolveClientId(clientId);
422
431
  const transport = await this.#findTransportWithDeviceId(deviceId);
423
- const signal = AbortSignal.timeout(10000);
424
432
  return this.#sendMessageWithTransport(transport, {
425
433
  deviceId,
426
434
  port,
427
- signal
428
- }, input, pipeline);
435
+ signal: signal ?? AbortSignal.timeout(10000)
436
+ }, input, pipeline, describeRequest(input));
429
437
  }
430
- async #sendMessageWithTransport(transport, options, input, pipeline) {
438
+ async #sendMessageWithTransport(transport, options, input, pipeline, request = "request") {
431
439
  const outputStream = await this.#connect(transport, options, ReadableStream.from([
432
440
  input
433
441
  ]), pipeline);
@@ -446,7 +454,7 @@ class Connector {
446
454
  if (response.done) {
447
455
  options.signal?.throwIfAborted();
448
456
  const clientId = ClientId.serialize(options.deviceId, options.port);
449
- throw new Error(`No response found for clientId: ${clientId}`);
457
+ throw new Error(`Transport ${transport.constructor.name} ended cleanly (EOF) while waiting for a response to ${request} on clientId: ${clientId}.`);
450
458
  } else result = response.value;
451
459
  } catch (err) {
452
460
  failed = true;
@@ -4,7 +4,7 @@ import { type AppInfo } from "../types.js";
4
4
  export interface DeviceConnectionSubscriber {
5
5
  readonly id: number;
6
6
  send(message: unknown): void;
7
- close(): void;
7
+ close(cause?: unknown): void;
8
8
  }
9
9
  /**
10
10
  * Maintains a persistent connection to a single device:port through a real
package/dist/f.js CHANGED
@@ -2115,7 +2115,7 @@ async function openAction(connector, params, signal) {
2115
2115
  signal
2116
2116
  } : {});
2117
2117
  signal?.throwIfAborted();
2118
- const response = await connector.openPage(clientId, params.url);
2118
+ const response = await connector.openPage(clientId, params.url, signal);
2119
2119
  return ok("open", {
2120
2120
  clientId,
2121
2121
  response
package/dist/f1.js CHANGED
@@ -219,7 +219,7 @@ class HDTTransport {
219
219
  hasError: false
220
220
  };
221
221
  try {
222
- const signal = AbortSignal.timeout(500);
222
+ const signal = AbortSignal.timeout(3000);
223
223
  const conn = _ts_add_disposable_resource(env, await this.#createWebSocketStream(signal), true);
224
224
  if ("ws://127.0.0.1:3005/ws" !== this.#url) try {
225
225
  await requestFreshClientList(conn.readable, conn.writable, signal);
@@ -503,7 +503,9 @@ class DaemonTransport {
503
503
  await this.#controlRequest("openApp", {
504
504
  deviceId,
505
505
  packageName,
506
- withDataCleared: options?.withDataCleared
506
+ withDataCleared: options?.withDataCleared,
507
+ restart: options?.restart,
508
+ schema: options?.schema
507
509
  });
508
510
  }
509
511
  async listClients() {
package/dist/h.js CHANGED
@@ -1,4 +1,4 @@
1
- import { AdbServerClient } from "@yume-chan/adb";
1
+ import { AdbServerClient, escapeArg } from "@yume-chan/adb";
2
2
  import node_net, { Server, Socket } from "node:net";
3
3
  import node_os, { platform } from "node:os";
4
4
  import { TransformStream as web_TransformStream, WritableStream as web_WritableStream } from "node:stream/web";
@@ -8822,12 +8822,14 @@ function parseLauncherActivityComponents(output) {
8822
8822
  return !/\s/u.test(line) && separatorIndex > 0 && separatorIndex === line.lastIndexOf("/") && separatorIndex < line.length - 1;
8823
8823
  });
8824
8824
  }
8825
- function createOpenAppCommandArgs(componentName) {
8825
+ function createOpenAppCommandArgs(componentName, restart) {
8826
8826
  return [
8827
8827
  "am",
8828
8828
  "start",
8829
8829
  "-W",
8830
- "-S",
8830
+ ...restart ? [
8831
+ "-S"
8832
+ ] : [],
8831
8833
  "-a",
8832
8834
  "android.intent.action.MAIN",
8833
8835
  "-c",
@@ -9043,7 +9045,7 @@ class AndroidTransport {
9043
9045
  throw error;
9044
9046
  }
9045
9047
  }
9046
- async openApp(deviceId, packageName, { withDataCleared } = {}) {
9048
+ async openApp(deviceId, packageName, { withDataCleared, schema, restart = true } = {}) {
9047
9049
  const env = {
9048
9050
  stack: [],
9049
9051
  error: void 0,
@@ -9067,17 +9069,35 @@ class AndroidTransport {
9067
9069
  ]);
9068
9070
  android_debug(`openApp clear data output ${output}`);
9069
9071
  }
9070
- const knownActivity = this.getKnownApp(packageName)?.activityName;
9071
- let componentName = knownActivity ? `${packageName}/${knownActivity}` : void 0;
9072
- if (!componentName) {
9073
- const queryOutput = await spawnWaitText(adb, createQueryLauncherActivitiesCommandArgs(packageName));
9074
- android_debug(`openApp launcher activities output ${queryOutput}`);
9075
- [componentName] = parseLauncherActivityComponents(queryOutput);
9072
+ let command;
9073
+ if (schema) command = [
9074
+ "am",
9075
+ "start",
9076
+ "-W",
9077
+ ...restart ? [
9078
+ "-S"
9079
+ ] : [],
9080
+ "-a",
9081
+ "android.intent.action.VIEW",
9082
+ "-d",
9083
+ escapeArg(schema),
9084
+ "-p",
9085
+ packageName
9086
+ ];
9087
+ else {
9088
+ const knownActivity = this.getKnownApp(packageName)?.activityName;
9089
+ let componentName = knownActivity ? `${packageName}/${knownActivity}` : void 0;
9090
+ if (!componentName) {
9091
+ const queryOutput = await spawnWaitText(adb, createQueryLauncherActivitiesCommandArgs(packageName));
9092
+ android_debug(`openApp launcher activities output ${queryOutput}`);
9093
+ [componentName] = parseLauncherActivityComponents(queryOutput);
9094
+ }
9095
+ if (!componentName) throw new Error(`No launchable activity found for package ${packageName}.`);
9096
+ command = createOpenAppCommandArgs(componentName, restart);
9076
9097
  }
9077
- if (!componentName) throw new Error(`No launchable activity found for package ${packageName}.`);
9078
- const output = await spawnWaitText(adb, createOpenAppCommandArgs(componentName));
9079
- android_debug(`openApp LAUNCHER output ${output}`);
9080
- if (output.includes("Error: Activity not started") || output.includes("unable to resolve Intent") || /Error type \d+/u.test(output)) throw new Error(`Failed to open app ${packageName}: ${output.trim()}`);
9098
+ const output = await spawnWaitText(adb, command);
9099
+ android_debug(`openApp output ${output}`);
9100
+ if (output.includes("Error:") || output.includes("unable to resolve Intent") || /Error type \d+/u.test(output)) throw new Error(`Failed to open app ${packageName}: ${output.trim()}`);
9081
9101
  } catch (e) {
9082
9102
  env.error = e;
9083
9103
  env.hasError = true;
package/dist/index.d.ts CHANGED
@@ -24,7 +24,7 @@ export declare class Connector {
24
24
  /**
25
25
  * Open a page on the given client by sending an `OpenCard` Customized event.
26
26
  */
27
- openPage(clientId: string, url: string): Promise<ListSessionResponse>;
27
+ openPage(clientId: string, url: string, signal?: AbortSignal): Promise<ListSessionResponse>;
28
28
  sendCDPMessage<Output, Params = never>(clientId: string, sessionId: number, method: string, params?: Params, isMainThread?: boolean): Promise<Output>;
29
29
  sendListSessionMessage(clientId: string): Promise<Session[]>;
30
30
  /**
package/dist/t.js CHANGED
@@ -138,6 +138,7 @@ class DeviceConnection {
138
138
  async #readLoop() {
139
139
  if (!this.#conn) return;
140
140
  let terminalCause;
141
+ let readFailed = false;
141
142
  try {
142
143
  for await (const message of this.#conn.readable){
143
144
  if (null === this.appInfo) {
@@ -151,21 +152,22 @@ class DeviceConnection {
151
152
  if (!isClientListMessage(message)) this.#broadcast(message);
152
153
  }
153
154
  } catch (err) {
155
+ readFailed = true;
154
156
  terminalCause = err;
155
157
  if (!this.#disposed) debug("read loop error on %s: %O", this.key, err);
156
158
  }
157
159
  if (!this.#disposed) {
158
160
  debug("device connection %s closed by remote", this.key);
159
- this.#terminate(terminalCause ?? new Error(null === this.appInfo ? `Device connection ${this.key} closed before Register` : `Device connection ${this.key} closed by remote`), true);
161
+ this.#terminate(terminalCause ?? new Error(null === this.appInfo ? `Device connection ${this.key} closed before Register` : `Device connection ${this.key} closed by remote`), true, !readFailed);
160
162
  }
161
163
  }
162
- #terminate(cause, readLoopEnded) {
164
+ #terminate(cause, readLoopEnded, cleanEof = false) {
163
165
  if (this.#disposed) return;
164
166
  this.#disposed = true;
165
167
  this.#terminalCause = cause;
166
168
  this.#rejectRegistration(cause);
167
169
  this.#startDisposal(!readLoopEnded);
168
- this.#closeAllSubscribers();
170
+ this.#closeAllSubscribers(cleanEof ? void 0 : cause);
169
171
  }
170
172
  #resolveRegistration(appInfo) {
171
173
  if (this.#registrationSettled) return;
@@ -178,9 +180,9 @@ class DeviceConnection {
178
180
  this.#registrationSettled = true;
179
181
  this.#rejectRegistered(reason);
180
182
  }
181
- #closeAllSubscribers() {
183
+ #closeAllSubscribers(cause) {
182
184
  for (const [, subscriber] of this.#subscribers)try {
183
- subscriber.close();
185
+ subscriber.close(cause);
184
186
  } catch (err) {
185
187
  debug("failed to close subscriber %d: %O", subscriber.id, err);
186
188
  }
@@ -896,11 +898,12 @@ class DevtoolDaemon {
896
898
  send (message) {
897
899
  if (!closing && 1 === ws.readyState) ws.send(JSON.stringify(message));
898
900
  },
899
- close: ()=>{
901
+ close: (cause)=>{
900
902
  if (closing) return;
901
903
  closing = true;
902
904
  this.#wsClients.delete(clientId);
903
- ws.close(1001, "device disconnected");
905
+ if (void 0 === cause) ws.close(1001, "device disconnected");
906
+ else ws.close(1011, websocketCloseReason(cause));
904
907
  }
905
908
  };
906
909
  session.send({
@@ -995,7 +998,9 @@ class DevtoolDaemon {
995
998
  if (!p.deviceId || !p.packageName) throw new Error("deviceId and packageName are required");
996
999
  const transport = await this.#findTransportWithDeviceId(p.deviceId);
997
1000
  await transport.openApp(p.deviceId, p.packageName, {
998
- withDataCleared: p.withDataCleared
1001
+ withDataCleared: p.withDataCleared,
1002
+ schema: p.schema,
1003
+ restart: p.restart
999
1004
  });
1000
1005
  result = null;
1001
1006
  break;
@@ -1238,6 +1243,26 @@ class DevtoolDaemon {
1238
1243
  }
1239
1244
  }
1240
1245
  }
1246
+ function websocketCloseReason(cause) {
1247
+ let summary;
1248
+ if (cause instanceof Error) {
1249
+ const code = cause.code;
1250
+ const codeText = "string" == typeof code || "number" == typeof code ? ` (${code})` : "";
1251
+ summary = `${cause.name}${codeText}: ${cause.message}`;
1252
+ } else summary = String(cause);
1253
+ const truncated = Buffer.byteLength(summary) > 123;
1254
+ const suffix = truncated ? "…" : "";
1255
+ const maxBytes = 123 - Buffer.byteLength(suffix);
1256
+ let reason = "";
1257
+ let byteLength = 0;
1258
+ for (const character of summary){
1259
+ const characterBytes = Buffer.byteLength(character);
1260
+ if (byteLength + characterBytes > maxBytes) break;
1261
+ reason += character;
1262
+ byteLength += characterBytes;
1263
+ }
1264
+ return reason + suffix;
1265
+ }
1241
1266
  function createDeviceConnectionSetupTimeoutError(key) {
1242
1267
  return new Error(`Timed out setting up device connection ${key} after ${DEVICE_CONN_SETUP_TIMEOUT_MS}ms`);
1243
1268
  }
@@ -19,5 +19,5 @@ export declare class AndroidTransport implements Transport {
19
19
  } | undefined;
20
20
  listAvailableApps(deviceId: string): Promise<App[]>;
21
21
  getAppIcon(deviceId: string, packageName: string): Promise<AppIcon>;
22
- openApp(deviceId: string, packageName: string, { withDataCleared }?: OpenAppOptions): Promise<void>;
22
+ openApp(deviceId: string, packageName: string, { withDataCleared, schema, restart }?: OpenAppOptions): Promise<void>;
23
23
  }
@@ -10,6 +10,10 @@ export declare function requireNumericPort(port: ClientTarget): number;
10
10
  export interface OpenAppOptions {
11
11
  signal?: AbortSignal;
12
12
  withDataCleared?: boolean | undefined;
13
+ /** Stop the app before launching; Android preserves its existing default of true. */
14
+ restart?: boolean | undefined;
15
+ /** Open a deep link instead of the launcher on supported transports; ignored otherwise. */
16
+ schema?: string | undefined;
13
17
  }
14
18
  export interface Transport {
15
19
  close(): Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lynx-js/devtool-connector",
3
- "version": "0.17.0",
3
+ "version": "0.18.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/lynx-community/skills.git",