spana-test 0.12.0 → 0.13.0

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 (161) hide show
  1. package/README.md +1 -1
  2. package/dist/agent/index.js +28 -10
  3. package/dist/agent/index.js.map +1 -1
  4. package/dist/api/app.d.ts +40 -0
  5. package/dist/api/app.d.ts.map +1 -1
  6. package/dist/api/expect.d.ts +13 -0
  7. package/dist/api/expect.d.ts.map +1 -1
  8. package/dist/app-W6PRRBMD.js +13 -0
  9. package/dist/appium-CC77BJNK.js +935 -0
  10. package/dist/appium-CC77BJNK.js.map +1 -0
  11. package/dist/bridge-server-S3DHK7XE.js +12 -0
  12. package/dist/channels/cdp-client.d.ts +13 -0
  13. package/dist/channels/cdp-client.d.ts.map +1 -1
  14. package/dist/channels/dom-channel.d.ts +1 -1
  15. package/dist/channels/dom-channel.d.ts.map +1 -1
  16. package/dist/chunk-27H6NDA5.js +845 -0
  17. package/dist/chunk-27H6NDA5.js.map +1 -0
  18. package/dist/chunk-4LJ3KYCX.js +94 -0
  19. package/dist/chunk-4LJ3KYCX.js.map +1 -0
  20. package/dist/chunk-5SDVP53E.js +1046 -0
  21. package/dist/chunk-5SDVP53E.js.map +1 -0
  22. package/dist/{chunk-OQRGR542.js → chunk-5T7LSBDM.js} +7 -7
  23. package/dist/chunk-5T7LSBDM.js.map +1 -0
  24. package/dist/{screenshot-compare-V4JQG73R.js → chunk-6C2EILMC.js} +185 -6
  25. package/dist/chunk-6C2EILMC.js.map +1 -0
  26. package/dist/{chunk-BWEQ4XT2.js → chunk-7IUD55GY.js} +455 -1178
  27. package/dist/chunk-7IUD55GY.js.map +1 -0
  28. package/dist/chunk-A7Z52TDQ.js +97 -0
  29. package/dist/chunk-A7Z52TDQ.js.map +1 -0
  30. package/dist/{chunk-AMBU26PB.js → chunk-BUNMIMGA.js} +2 -2
  31. package/dist/chunk-DMF2BPPA.js +547 -0
  32. package/dist/chunk-DMF2BPPA.js.map +1 -0
  33. package/dist/chunk-FUXFXFBM.js +1962 -0
  34. package/dist/chunk-FUXFXFBM.js.map +1 -0
  35. package/dist/{chunk-F2YUBD4E.js → chunk-FV7ONGQ7.js} +3 -3
  36. package/dist/{chunk-QOL44BNJ.js → chunk-GDVHJBR2.js} +4 -4
  37. package/dist/chunk-GLNTGHR6.js +330 -0
  38. package/dist/chunk-GLNTGHR6.js.map +1 -0
  39. package/dist/chunk-HJY5YN4N.js +272 -0
  40. package/dist/chunk-HJY5YN4N.js.map +1 -0
  41. package/dist/chunk-HNQLWFHL.js +40 -0
  42. package/dist/chunk-HNQLWFHL.js.map +1 -0
  43. package/dist/chunk-HUYC4OAL.js +72 -0
  44. package/dist/chunk-HUYC4OAL.js.map +1 -0
  45. package/dist/chunk-HWS3XUEF.js +109 -0
  46. package/dist/chunk-HWS3XUEF.js.map +1 -0
  47. package/dist/{chunk-F3AFZ6UX.js → chunk-IDIHDVGC.js} +3 -1
  48. package/dist/chunk-IDIHDVGC.js.map +1 -0
  49. package/dist/{chunk-53TGNQTM.js → chunk-IUK3RJ6W.js} +32 -18
  50. package/dist/{chunk-53TGNQTM.js.map → chunk-IUK3RJ6W.js.map} +1 -1
  51. package/dist/chunk-K4K2ACT2.js +179 -0
  52. package/dist/chunk-K4K2ACT2.js.map +1 -0
  53. package/dist/chunk-LKGF75QJ.js +654 -0
  54. package/dist/chunk-LKGF75QJ.js.map +1 -0
  55. package/dist/chunk-MAKZK7GY.js +935 -0
  56. package/dist/chunk-MAKZK7GY.js.map +1 -0
  57. package/dist/chunk-MPJCUL2B.js +154 -0
  58. package/dist/chunk-MPJCUL2B.js.map +1 -0
  59. package/dist/chunk-MUMIMDRJ.js +24 -0
  60. package/dist/chunk-MUMIMDRJ.js.map +1 -0
  61. package/dist/{chunk-XQRXQBDQ.js → chunk-NWGA3R2E.js} +2 -19
  62. package/dist/chunk-NWGA3R2E.js.map +1 -0
  63. package/dist/chunk-PPRNCRTS.js +1104 -0
  64. package/dist/chunk-PPRNCRTS.js.map +1 -0
  65. package/dist/{chunk-LQQNE2OE.js → chunk-RHQJSPOS.js} +371 -40
  66. package/dist/chunk-RHQJSPOS.js.map +1 -0
  67. package/dist/{chunk-GAWJL6Q3.js → chunk-VWJNINPX.js} +490 -89
  68. package/dist/chunk-VWJNINPX.js.map +1 -0
  69. package/dist/chunk-WFC4DCFF.js +529 -0
  70. package/dist/chunk-WFC4DCFF.js.map +1 -0
  71. package/dist/chunk-X5FRYDZ3.js +91 -0
  72. package/dist/chunk-X5FRYDZ3.js.map +1 -0
  73. package/dist/chunk-YFTHJRDO.js +37 -0
  74. package/dist/chunk-YFTHJRDO.js.map +1 -0
  75. package/dist/cli/test-command.d.ts.map +1 -1
  76. package/dist/cli.js +18 -18
  77. package/dist/config-loader-7W7OEWRG.js +10 -0
  78. package/dist/core/engine.d.ts.map +1 -1
  79. package/dist/{discover-43C3BE7I.js → discover-6ULCTB5T.js} +3 -3
  80. package/dist/{doctor-command-CLKEEOAX.js → doctor-command-4CQQLB7M.js} +16 -9
  81. package/dist/{doctor-command-CLKEEOAX.js.map → doctor-command-4CQQLB7M.js.map} +1 -1
  82. package/dist/driver-3MEIFYST.js +19 -0
  83. package/dist/driver-QTIAADUZ.js +19 -0
  84. package/dist/drivers/cdp-browser.d.ts +27 -0
  85. package/dist/drivers/cdp-browser.d.ts.map +1 -1
  86. package/dist/drivers/electron.d.ts +1 -1
  87. package/dist/drivers/electron.d.ts.map +1 -1
  88. package/dist/drivers/playwright.d.ts +1 -5
  89. package/dist/drivers/playwright.d.ts.map +1 -1
  90. package/dist/drivers/raw-driver.d.ts +4 -0
  91. package/dist/drivers/raw-driver.d.ts.map +1 -1
  92. package/dist/drivers/wasm-utils.d.ts +100 -0
  93. package/dist/drivers/wasm-utils.d.ts.map +1 -0
  94. package/dist/drivers/wasm.d.ts +57 -0
  95. package/dist/drivers/wasm.d.ts.map +1 -0
  96. package/dist/electrobun-MPAHMSI2.js +15 -0
  97. package/dist/electrobun-MPAHMSI2.js.map +1 -0
  98. package/dist/electron-SQACDON3.js +9 -0
  99. package/dist/electron-SQACDON3.js.map +1 -0
  100. package/dist/index.d.ts +3 -0
  101. package/dist/index.d.ts.map +1 -1
  102. package/dist/index.js +400 -53
  103. package/dist/index.js.map +1 -1
  104. package/dist/installer-KL2NCILK.js +17 -0
  105. package/dist/installer-KL2NCILK.js.map +1 -0
  106. package/dist/{local-RH5EFGYF.js → local-SWHWINSA.js} +8 -9
  107. package/dist/local-SWHWINSA.js.map +1 -0
  108. package/dist/pagesource-KIQ5T5MA.js +9 -0
  109. package/dist/pagesource-KIQ5T5MA.js.map +1 -0
  110. package/dist/pagesource-KKG7WMFJ.js +9 -0
  111. package/dist/pagesource-KKG7WMFJ.js.map +1 -0
  112. package/dist/playwright-42QYIZEE.js +28 -0
  113. package/dist/playwright-42QYIZEE.js.map +1 -0
  114. package/dist/runtime/local.d.ts.map +1 -1
  115. package/dist/schemas/config.d.ts +32 -0
  116. package/dist/schemas/config.d.ts.map +1 -1
  117. package/dist/schemas/device.d.ts +1 -1
  118. package/dist/schemas/device.d.ts.map +1 -1
  119. package/dist/screenshot-compare-BJRJHKNQ.js +12 -0
  120. package/dist/screenshot-compare-BJRJHKNQ.js.map +1 -0
  121. package/dist/{server-D45AO34E.js → server-2Y46CDVB.js} +30 -12
  122. package/dist/{server-D45AO34E.js.map → server-2Y46CDVB.js.map} +1 -1
  123. package/dist/{server-KLZBJOMQ.js → server-ZCBZ4UYF.js} +2 -2
  124. package/dist/server-ZCBZ4UYF.js.map +1 -0
  125. package/dist/session-5XW6TKF4.js +39 -0
  126. package/dist/session-5XW6TKF4.js.map +1 -0
  127. package/dist/smart/coordinator.d.ts.map +1 -1
  128. package/dist/{studio-command-TNSJGTFA.js → studio-command-BNBOL424.js} +2 -2
  129. package/dist/{test-command-EXPYFDTF.js → test-command-T4PLAZXU.js} +58 -1036
  130. package/dist/test-command-T4PLAZXU.js.map +1 -0
  131. package/dist/watch-mode-NR5MHNNL.js +10 -0
  132. package/dist/watch-mode-NR5MHNNL.js.map +1 -0
  133. package/native/win32-x64/spana_native.dll +0 -0
  134. package/package.json +2 -2
  135. package/dist/app-CBHH5GMB.js +0 -10
  136. package/dist/chunk-BWEQ4XT2.js.map +0 -1
  137. package/dist/chunk-F3AFZ6UX.js.map +0 -1
  138. package/dist/chunk-GAWJL6Q3.js.map +0 -1
  139. package/dist/chunk-GDDCZ2PL.js +0 -2619
  140. package/dist/chunk-GDDCZ2PL.js.map +0 -1
  141. package/dist/chunk-LQQNE2OE.js.map +0 -1
  142. package/dist/chunk-OQRGR542.js.map +0 -1
  143. package/dist/chunk-PPAPRKQU.js +0 -4739
  144. package/dist/chunk-PPAPRKQU.js.map +0 -1
  145. package/dist/chunk-VOYJQDSI.js +0 -188
  146. package/dist/chunk-VOYJQDSI.js.map +0 -1
  147. package/dist/chunk-XQRXQBDQ.js.map +0 -1
  148. package/dist/config-loader-V26XXHPH.js +0 -10
  149. package/dist/screenshot-compare-V4JQG73R.js.map +0 -1
  150. package/dist/session-N6DEYVPM.js +0 -21
  151. package/dist/test-command-EXPYFDTF.js.map +0 -1
  152. /package/dist/{app-CBHH5GMB.js.map → app-W6PRRBMD.js.map} +0 -0
  153. /package/dist/{config-loader-V26XXHPH.js.map → bridge-server-S3DHK7XE.js.map} +0 -0
  154. /package/dist/{chunk-AMBU26PB.js.map → chunk-BUNMIMGA.js.map} +0 -0
  155. /package/dist/{chunk-F2YUBD4E.js.map → chunk-FV7ONGQ7.js.map} +0 -0
  156. /package/dist/{chunk-QOL44BNJ.js.map → chunk-GDVHJBR2.js.map} +0 -0
  157. /package/dist/{discover-43C3BE7I.js.map → config-loader-7W7OEWRG.js.map} +0 -0
  158. /package/dist/{local-RH5EFGYF.js.map → discover-6ULCTB5T.js.map} +0 -0
  159. /package/dist/{server-KLZBJOMQ.js.map → driver-3MEIFYST.js.map} +0 -0
  160. /package/dist/{session-N6DEYVPM.js.map → driver-QTIAADUZ.js.map} +0 -0
  161. /package/dist/{studio-command-TNSJGTFA.js.map → studio-command-BNBOL424.js.map} +0 -0
package/dist/index.js CHANGED
@@ -29,7 +29,7 @@ import {
29
29
  withActiveStepRecorder,
30
30
  writeRichTraceBundle,
31
31
  writeWorkerProcessReport
32
- } from "./chunk-OQRGR542.js";
32
+ } from "./chunk-5T7LSBDM.js";
33
33
  import {
34
34
  NetworkEventBuffer,
35
35
  SPANA_MCP_TOOLS,
@@ -38,7 +38,7 @@ import {
38
38
  buildFlowFileFromLines,
39
39
  buildPerformanceProfileScript,
40
40
  formatSelectorCode
41
- } from "./chunk-F2YUBD4E.js";
41
+ } from "./chunk-FV7ONGQ7.js";
42
42
  import {
43
43
  clearReplayCache,
44
44
  formatCacheInspectTable,
@@ -63,29 +63,22 @@ import {
63
63
  } from "./chunk-FSPMFRJO.js";
64
64
  import {
65
65
  defineConfig
66
- } from "./chunk-F3AFZ6UX.js";
66
+ } from "./chunk-IDIHDVGC.js";
67
67
  import "./chunk-U56N5JCJ.js";
68
68
  import {
69
- UPLOAD_ATTACH_TIMEOUT_MS,
70
- applyExtensionChromeArgs,
71
69
  defineDomTransport,
72
70
  defineDriverAdapter,
73
- getLoadedExtensions,
74
- launchDirectCdpBrowser,
75
71
  listDomTransports,
76
72
  listDriverAdapters,
77
- makeLightweightCdpDriver,
78
73
  registerDomTransport,
79
74
  registerDriverAdapter,
80
- resolveBrowserExtensions,
81
75
  resolveDomTransport,
82
76
  resolveDriverAdapter,
83
77
  resolveWebEngine,
84
- runOAuthPopupFlow,
85
78
  speculativelyPrelaunchWebBrowser,
86
79
  unregisterDomTransport,
87
80
  unregisterDriverAdapter
88
- } from "./chunk-BWEQ4XT2.js";
81
+ } from "./chunk-PPRNCRTS.js";
89
82
  import {
90
83
  ReplayCacheStore,
91
84
  ReplaySession,
@@ -99,42 +92,27 @@ import {
99
92
  secret,
100
93
  unique
101
94
  } from "./chunk-HIGFQRWM.js";
95
+ import "./chunk-PRQTAIYA.js";
96
+ import {
97
+ cloneIOSSimulator,
98
+ deleteIOSSimulator
99
+ } from "./chunk-2MA5G2VH.js";
100
+ import "./chunk-YFTHJRDO.js";
102
101
  import {
103
102
  connectPlaywrightOverCDP,
104
103
  connectPlaywrightOverWS,
105
104
  ensureWarmBrowserDaemon,
106
- launchPlaywrightBrowser,
107
- makeElectronDriver
108
- } from "./chunk-PPAPRKQU.js";
109
- import {
110
- AndroidWebViewCdpChannel,
111
- AppleWebInspectorClient,
112
- CdpDomChannel,
113
- SpanaBridgeChannel,
114
- TARGET_CHANNEL_MATRIX,
115
- WebKitInspectorChannel,
116
- createAndroidWebViewCdpChannel,
117
- createCdpDomChannel,
118
- createCompositeDomChannel,
119
- createSpanaBridgeChannel,
120
- createWebKitInspectorChannel,
121
- decodeWebInspectorFrames,
122
- encodeWebInspectorPacket,
123
- findSimulatorWebInspectorSocket,
124
- formatTargetMatrixTable,
125
- makeElectrobunDriver,
126
- parseAndroidWebViewSockets,
127
- parseWebInspectorXmlFrame,
128
- resolveElectrobunEngine,
129
- resolveElectrobunLaunchPlan,
130
- resolveTargetDescriptor
131
- } from "./chunk-GDDCZ2PL.js";
132
- import "./chunk-XVL4FHXA.js";
105
+ launchPlaywrightBrowser
106
+ } from "./chunk-FUXFXFBM.js";
133
107
  import {
134
- cloneIOSSimulator,
135
- deleteIOSSimulator
136
- } from "./chunk-2MA5G2VH.js";
137
- import "./chunk-XD6A3VXB.js";
108
+ UPLOAD_ATTACH_TIMEOUT_MS,
109
+ applyExtensionChromeArgs,
110
+ getLoadedExtensions,
111
+ launchDirectCdpBrowser,
112
+ makeLightweightCdpDriver,
113
+ resolveBrowserExtensions,
114
+ runOAuthPopupFlow
115
+ } from "./chunk-7IUD55GY.js";
138
116
  import {
139
117
  DEFAULT_WARM_DAEMON_IDLE_TTL_MS,
140
118
  defaultDaemonStateDir,
@@ -146,18 +124,48 @@ import {
146
124
  sweepOrphanedSpanaBrowsers,
147
125
  updateWarmDaemonSession
148
126
  } from "./chunk-FHCOPLYB.js";
127
+ import {
128
+ makeElectronDriver
129
+ } from "./chunk-GLNTGHR6.js";
130
+ import {
131
+ TARGET_CHANNEL_MATRIX,
132
+ formatTargetMatrixTable,
133
+ makeElectrobunDriver,
134
+ resolveElectrobunEngine,
135
+ resolveElectrobunLaunchPlan,
136
+ resolveTargetDescriptor
137
+ } from "./chunk-WFC4DCFF.js";
138
+ import {
139
+ AppleWebInspectorClient,
140
+ WebKitInspectorChannel,
141
+ createWebKitInspectorChannel,
142
+ decodeWebInspectorFrames,
143
+ encodeWebInspectorPacket,
144
+ findSimulatorWebInspectorSocket,
145
+ parseWebInspectorXmlFrame
146
+ } from "./chunk-LKGF75QJ.js";
147
+ import {
148
+ AndroidWebViewCdpChannel,
149
+ createAndroidWebViewCdpChannel,
150
+ parseAndroidWebViewSockets
151
+ } from "./chunk-HJY5YN4N.js";
152
+ import "./chunk-HWS3XUEF.js";
153
+ import "./chunk-HNQLWFHL.js";
149
154
  import {
150
155
  allocateFreePort,
151
156
  assertPortAvailable,
152
157
  isPortAvailable
153
158
  } from "./chunk-7Q7TSUNL.js";
154
- import "./chunk-PRQTAIYA.js";
159
+ import "./chunk-XVL4FHXA.js";
155
160
  import {
156
- comparePngNative,
157
- getNativeAcceleratorPath,
158
- isNativeAcceleratorActive,
159
- tokenizeXmlNative
160
- } from "./chunk-VOYJQDSI.js";
161
+ SpanaBridgeChannel,
162
+ createCompositeDomChannel,
163
+ createSpanaBridgeChannel
164
+ } from "./chunk-DMF2BPPA.js";
165
+ import {
166
+ CdpDomChannel,
167
+ createCdpDomChannel
168
+ } from "./chunk-MAKZK7GY.js";
161
169
  import {
162
170
  and,
163
171
  assertDataSnapshot,
@@ -184,10 +192,12 @@ import {
184
192
  resolveElementAcrossChannels,
185
193
  systemUI,
186
194
  within
187
- } from "./chunk-LQQNE2OE.js";
188
- import "./chunk-XQRXQBDQ.js";
195
+ } from "./chunk-RHQJSPOS.js";
196
+ import "./chunk-MUMIMDRJ.js";
197
+ import "./chunk-NWGA3R2E.js";
189
198
  import {
190
199
  SPANA_INJECTED_RUNTIME_SCRIPT,
200
+ SPANA_WASM_HOOK_SCRIPT,
191
201
  buildDomActionabilityDiagScript,
192
202
  buildDomFillScript,
193
203
  buildDomQueryScript,
@@ -196,8 +206,21 @@ import {
196
206
  buildDomWaitForHiddenScript,
197
207
  buildDomWaitForMatchScript,
198
208
  buildDomWaitForSelectorScript,
199
- buildInjectedCallScript
200
- } from "./chunk-GAWJL6Q3.js";
209
+ buildInjectedCallScript,
210
+ formatByteSize,
211
+ isWasmTrapError,
212
+ parseByteSize,
213
+ resolveChromiumGpuArgs
214
+ } from "./chunk-VWJNINPX.js";
215
+ import {
216
+ DriverError
217
+ } from "./chunk-A7Z52TDQ.js";
218
+ import {
219
+ comparePngNative,
220
+ getNativeAcceleratorPath,
221
+ isNativeAcceleratorActive,
222
+ tokenizeXmlNative
223
+ } from "./chunk-6C2EILMC.js";
201
224
  import {
202
225
  init_esm_shims
203
226
  } from "./chunk-FTXUQMGH.js";
@@ -279,7 +302,8 @@ var DeviceInfo = Schema2.Struct({
279
302
  "wda",
280
303
  "appium",
281
304
  "electron",
282
- "electrobun"
305
+ "electrobun",
306
+ "wasm"
283
307
  ])
284
308
  });
285
309
 
@@ -1127,6 +1151,322 @@ var BidiDomChannel = class {
1127
1151
  function createBidiDomChannel(options) {
1128
1152
  return new BidiDomChannel(options);
1129
1153
  }
1154
+
1155
+ // src/drivers/wasm.ts
1156
+ init_esm_shims();
1157
+ import { readFile } from "fs/promises";
1158
+ import { execFile } from "child_process";
1159
+ import { promisify } from "util";
1160
+ import { Effect } from "effect";
1161
+ var execFileAsync = promisify(execFile);
1162
+ function emptyRoot() {
1163
+ return {
1164
+ id: "wasm-root",
1165
+ elementType: "WasmModule",
1166
+ bounds: { x: 0, y: 0, width: 1280, height: 720 },
1167
+ enabled: true,
1168
+ visible: true,
1169
+ clickable: false,
1170
+ children: []
1171
+ };
1172
+ }
1173
+ function findPrimaryMemory(exports) {
1174
+ if (!exports) return void 0;
1175
+ if (exports.memory instanceof WebAssembly.Memory) return exports.memory;
1176
+ for (const val of Object.values(exports)) {
1177
+ if (val instanceof WebAssembly.Memory) return val;
1178
+ }
1179
+ return void 0;
1180
+ }
1181
+ function createWasmDriver(options) {
1182
+ return Effect.sync(() => {
1183
+ const runtime = options.runtime ?? "in-process";
1184
+ let instance = null;
1185
+ let compiledModule = null;
1186
+ let lastBytes = null;
1187
+ let peakMemoryBytes = 0;
1188
+ let instantiateMs = 0;
1189
+ let moduleCount = 0;
1190
+ const consoleLogs = [];
1191
+ const jsErrors = [];
1192
+ const wasmTraps = [];
1193
+ const recordError = (err) => {
1194
+ const name = err instanceof Error ? err.name : "Error";
1195
+ const message = err instanceof Error ? err.message : String(err);
1196
+ const stack = err instanceof Error ? err.stack : void 0;
1197
+ jsErrors.push({ name, message, stack });
1198
+ if (isWasmTrapError({ name, message, stack }) || err instanceof WebAssembly.RuntimeError) {
1199
+ wasmTraps.push({
1200
+ name,
1201
+ message,
1202
+ source: "wasm",
1203
+ stack,
1204
+ timestamp: Date.now()
1205
+ });
1206
+ }
1207
+ };
1208
+ const readMemoryBytes = () => {
1209
+ const mem = findPrimaryMemory(instance?.exports ?? null);
1210
+ const bytes = mem ? mem.buffer.byteLength : 0;
1211
+ if (bytes > peakMemoryBytes) peakMemoryBytes = bytes;
1212
+ return bytes;
1213
+ };
1214
+ const loadBytes = async (bundleId) => {
1215
+ if (options.wasmBytes) return options.wasmBytes;
1216
+ const targetPath = options.modulePath || (bundleId && bundleId.endsWith(".wasm") ? bundleId : void 0);
1217
+ if (!targetPath) {
1218
+ throw new Error("WASM driver requires `modulePath` or `wasmBytes`.");
1219
+ }
1220
+ const buf = await readFile(targetPath);
1221
+ return new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);
1222
+ };
1223
+ const instantiateNow = async (bundleId) => {
1224
+ const t0 = performance.now();
1225
+ const bytes = await loadBytes(bundleId);
1226
+ lastBytes = bytes;
1227
+ if (runtime === "wasmtime") {
1228
+ const binary = options.wasmtimeBinary ?? "wasmtime";
1229
+ const cliArgs = [];
1230
+ for (const [guest, host] of Object.entries(options.preopens ?? {})) {
1231
+ cliArgs.push("--dir", `${host}::${guest}`);
1232
+ }
1233
+ for (const [k, v] of Object.entries(options.env ?? {})) {
1234
+ cliArgs.push("--env", `${k}=${v}`);
1235
+ }
1236
+ if (!options.modulePath) {
1237
+ throw new Error('WASM runtime "wasmtime" requires `modulePath` on disk.');
1238
+ }
1239
+ cliArgs.push(options.modulePath, ...options.args ?? []);
1240
+ try {
1241
+ const { stdout, stderr } = await execFileAsync(binary, cliArgs, { encoding: "utf8" });
1242
+ if (stdout.trim()) consoleLogs.push({ type: "log", text: stdout.trim() });
1243
+ if (stderr.trim()) consoleLogs.push({ type: "error", text: stderr.trim() });
1244
+ moduleCount += 1;
1245
+ instantiateMs = Math.round(performance.now() - t0);
1246
+ } catch (err) {
1247
+ if (err?.stdout) consoleLogs.push({ type: "log", text: String(err.stdout).trim() });
1248
+ if (err?.stderr) consoleLogs.push({ type: "error", text: String(err.stderr).trim() });
1249
+ recordError(err);
1250
+ throw err;
1251
+ }
1252
+ return;
1253
+ }
1254
+ if (runtime === "wasi") {
1255
+ const { WASI } = await import("wasi");
1256
+ const wasi = new WASI({
1257
+ version: "preview1",
1258
+ args: [options.modulePath ?? "module.wasm", ...options.args ?? []],
1259
+ env: options.env ?? {},
1260
+ preopens: options.preopens ?? {}
1261
+ });
1262
+ const mod = await WebAssembly.compile(bytes);
1263
+ compiledModule = mod;
1264
+ const imports = {
1265
+ ...wasi.getImportObject(),
1266
+ ...options.imports
1267
+ };
1268
+ const inst = await WebAssembly.instantiate(mod, imports);
1269
+ instance = inst;
1270
+ moduleCount += 1;
1271
+ readMemoryBytes();
1272
+ instantiateMs = Math.round(performance.now() - t0);
1273
+ try {
1274
+ if (typeof inst.exports._start === "function") {
1275
+ wasi.start(inst);
1276
+ } else if (typeof inst.exports._initialize === "function") {
1277
+ wasi.initialize(inst);
1278
+ }
1279
+ } catch (err) {
1280
+ recordError(err);
1281
+ throw err;
1282
+ }
1283
+ readMemoryBytes();
1284
+ return;
1285
+ }
1286
+ try {
1287
+ const mod = await WebAssembly.compile(bytes);
1288
+ compiledModule = mod;
1289
+ const inst = await WebAssembly.instantiate(mod, options.imports ?? {});
1290
+ instance = inst;
1291
+ moduleCount += 1;
1292
+ readMemoryBytes();
1293
+ instantiateMs = Math.round(performance.now() - t0);
1294
+ if (options.entryExport && typeof inst.exports[options.entryExport] === "function") {
1295
+ inst.exports[options.entryExport]();
1296
+ readMemoryBytes();
1297
+ }
1298
+ } catch (err) {
1299
+ recordError(err);
1300
+ throw err;
1301
+ }
1302
+ };
1303
+ const buildEvalContext = () => {
1304
+ const exports = instance?.exports ?? {};
1305
+ const memory = findPrimaryMemory(exports);
1306
+ const decoder = new TextDecoder();
1307
+ const encoder = new TextEncoder();
1308
+ return {
1309
+ exports,
1310
+ memory,
1311
+ readUtf8(ptr, byteLength) {
1312
+ if (!memory) throw new Error("WASM module does not export linear memory");
1313
+ return decoder.decode(new Uint8Array(memory.buffer, ptr, byteLength));
1314
+ },
1315
+ writeUtf8(ptr, text) {
1316
+ if (!memory) throw new Error("WASM module does not export linear memory");
1317
+ const encoded = encoder.encode(text);
1318
+ new Uint8Array(memory.buffer, ptr, encoded.byteLength).set(encoded);
1319
+ return encoded.byteLength;
1320
+ }
1321
+ };
1322
+ };
1323
+ const getMetrics = () => {
1324
+ const bytes = readMemoryBytes();
1325
+ return {
1326
+ moduleCount,
1327
+ pendingCount: 0,
1328
+ wasmMemoryBytes: bytes,
1329
+ wasmMemoryPages: Math.round(bytes / 65536),
1330
+ peakWasmMemoryBytes: peakMemoryBytes,
1331
+ crossOriginIsolated: true,
1332
+ sharedArrayBufferAvailable: typeof SharedArrayBuffer !== "undefined",
1333
+ traps: [...wasmTraps],
1334
+ modules: moduleCount > 0 ? [
1335
+ {
1336
+ id: 1,
1337
+ name: options.modulePath,
1338
+ sizeBytes: lastBytes?.byteLength,
1339
+ instantiateMs,
1340
+ memoryBytes: bytes,
1341
+ memoryPages: Math.round(bytes / 65536),
1342
+ instantiatedAt: Date.now()
1343
+ }
1344
+ ] : []
1345
+ };
1346
+ };
1347
+ const service = {
1348
+ beginFlow: () => Effect.sync(() => {
1349
+ consoleLogs.length = 0;
1350
+ jsErrors.length = 0;
1351
+ wasmTraps.length = 0;
1352
+ }),
1353
+ launchApp: (bundleId) => Effect.tryPromise({
1354
+ try: () => instantiateNow(bundleId),
1355
+ catch: (e) => new DriverError({ message: `WASM launchApp failed: ${e}` })
1356
+ }),
1357
+ stopApp: () => Effect.sync(() => {
1358
+ instance = null;
1359
+ }),
1360
+ killApp: () => Effect.sync(() => {
1361
+ instance = null;
1362
+ compiledModule = null;
1363
+ }),
1364
+ clearAppState: (bundleId) => Effect.tryPromise({
1365
+ try: async () => {
1366
+ instance = null;
1367
+ consoleLogs.length = 0;
1368
+ jsErrors.length = 0;
1369
+ wasmTraps.length = 0;
1370
+ if (lastBytes || options.modulePath || options.wasmBytes) {
1371
+ await instantiateNow(bundleId);
1372
+ }
1373
+ },
1374
+ catch: (e) => new DriverError({ message: `WASM clearAppState failed: ${e}` })
1375
+ }),
1376
+ dumpHierarchy: () => Effect.tryPromise({
1377
+ try: async () => {
1378
+ if (!instance) return JSON.stringify(emptyRoot());
1379
+ const mem = findPrimaryMemory(instance.exports);
1380
+ if (options.treeProvider) {
1381
+ const tree = await options.treeProvider(instance.exports, mem);
1382
+ return JSON.stringify(tree);
1383
+ }
1384
+ return JSON.stringify({
1385
+ ...emptyRoot(),
1386
+ text: options.modulePath ?? "wasm-module",
1387
+ attributes: {
1388
+ exports: Object.keys(instance.exports).join(","),
1389
+ wasmMemoryBytes: String(readMemoryBytes())
1390
+ }
1391
+ });
1392
+ },
1393
+ catch: (e) => new DriverError({ message: `WASM dumpHierarchy failed: ${e}` })
1394
+ }),
1395
+ evaluate: (script, ...args) => Effect.tryPromise({
1396
+ try: async () => {
1397
+ if (!instance && (options.modulePath || options.wasmBytes)) {
1398
+ await instantiateNow();
1399
+ }
1400
+ const ctx = buildEvalContext();
1401
+ try {
1402
+ const res = typeof script === "function" ? await script(ctx, ...args) : await new Function("wasm", "exports", "memory", `return (${script})`)(
1403
+ ctx,
1404
+ ctx.exports,
1405
+ ctx.memory
1406
+ );
1407
+ readMemoryBytes();
1408
+ return res;
1409
+ } catch (err) {
1410
+ recordError(err);
1411
+ throw err;
1412
+ }
1413
+ },
1414
+ catch: (e) => new DriverError({
1415
+ message: `WASM evaluate failed: ${e instanceof Error ? e.message : String(e)}`
1416
+ })
1417
+ }),
1418
+ getWasmMetrics: () => Effect.sync(() => getMetrics()),
1419
+ getWasmTraps: () => Effect.sync(() => [...wasmTraps]),
1420
+ getConsoleLogs: () => Effect.sync(() => [...consoleLogs]),
1421
+ getJSErrors: () => Effect.sync(() => [...jsErrors]),
1422
+ tapAtCoordinate: () => Effect.void,
1423
+ doubleTapAtCoordinate: () => Effect.void,
1424
+ longPressAtCoordinate: () => Effect.void,
1425
+ swipe: () => Effect.void,
1426
+ inputText: () => Effect.void,
1427
+ pressKey: () => Effect.void,
1428
+ hideKeyboard: () => Effect.void,
1429
+ takeScreenshot: () => Effect.sync(() => new Uint8Array()),
1430
+ getDeviceInfo: () => Effect.sync(() => ({
1431
+ deviceId: options.modulePath ?? "wasm-in-process",
1432
+ name: `Spana WASM (${runtime}${compiledModule ? ", loaded" : ""})`,
1433
+ platform: "web",
1434
+ isEmulator: false,
1435
+ screenWidth: 1280,
1436
+ screenHeight: 720,
1437
+ driverType: "wasm"
1438
+ })),
1439
+ openLink: () => Effect.void,
1440
+ back: () => Effect.void
1441
+ };
1442
+ return service;
1443
+ });
1444
+ }
1445
+ function createWasmDriverAdapter(defaults = {}) {
1446
+ return defineDriverAdapter({
1447
+ name: "wasm",
1448
+ platforms: ["wasm", "web"],
1449
+ engines: ["wasm", "wasi", "wasmtime"],
1450
+ description: "Headless WebAssembly & WASI driver adapter (in-process, node:wasi, or wasmtime)",
1451
+ async create(ctx) {
1452
+ const merged = {
1453
+ ...defaults,
1454
+ ...ctx.options,
1455
+ modulePath: ctx.options?.modulePath ?? defaults.modulePath ?? (ctx.appId.endsWith(".wasm") ? ctx.resolvePath(ctx.appId) : void 0)
1456
+ };
1457
+ const driver = await Effect.runPromise(createWasmDriver(merged));
1458
+ return {
1459
+ driver,
1460
+ parseHierarchy: (raw) => JSON.parse(raw),
1461
+ cleanup: async () => {
1462
+ await Effect.runPromise(driver.killApp(ctx.appId)).catch(() => {
1463
+ });
1464
+ },
1465
+ metadata: { runtime: merged.runtime ?? "in-process", modulePath: merged.modulePath }
1466
+ };
1467
+ }
1468
+ });
1469
+ }
1130
1470
  export {
1131
1471
  AndroidWebViewCdpChannel,
1132
1472
  AppleWebInspectorClient,
@@ -1141,6 +1481,7 @@ export {
1141
1481
  ReplaySession,
1142
1482
  SPANA_INJECTED_RUNTIME_SCRIPT,
1143
1483
  SPANA_MCP_TOOLS,
1484
+ SPANA_WASM_HOOK_SCRIPT,
1144
1485
  SpanaBridgeChannel,
1145
1486
  SpanaMcpServer,
1146
1487
  TARGET_CHANNEL_MATRIX,
@@ -1199,6 +1540,8 @@ export {
1199
1540
  createOpenAICompatibleAgentProvider,
1200
1541
  createRemoteFlowClaimer,
1201
1542
  createSpanaBridgeChannel,
1543
+ createWasmDriver,
1544
+ createWasmDriverAdapter,
1202
1545
  createWebKitInspectorChannel,
1203
1546
  decisionFilter,
1204
1547
  decodeWebInspectorFrames,
@@ -1224,6 +1567,7 @@ export {
1224
1567
  first,
1225
1568
  flow,
1226
1569
  formatActionsAsFlowCode,
1570
+ formatByteSize,
1227
1571
  formatCacheInspectTable,
1228
1572
  formatCodeFrame,
1229
1573
  formatFilterSummary,
@@ -1245,6 +1589,7 @@ export {
1245
1589
  isSystemUISelector,
1246
1590
  isTcpPortOpen,
1247
1591
  isTestIDSelector,
1592
+ isWasmTrapError,
1248
1593
  last,
1249
1594
  launchDirectCdpBrowser,
1250
1595
  launchPlaywrightBrowser,
@@ -1259,6 +1604,7 @@ export {
1259
1604
  or,
1260
1605
  orderFlowsLongestFirst,
1261
1606
  parseAndroidWebViewSockets,
1607
+ parseByteSize,
1262
1608
  parseWebInspectorXmlFrame,
1263
1609
  partitionFlowsAcrossProcesses,
1264
1610
  pathRuleFilter,
@@ -1270,6 +1616,7 @@ export {
1270
1616
  renderTraceViewerHtml,
1271
1617
  replayRecordedAction,
1272
1618
  resolveBrowserExtensions,
1619
+ resolveChromiumGpuArgs,
1273
1620
  resolveDomTransport,
1274
1621
  resolveDriverAdapter,
1275
1622
  resolveElectrobunEngine,