@midscene/ios 1.0.1-beta-20251104075048.0 → 1.0.1-beta-20251106111345.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.
package/dist/es/bin.mjs CHANGED
@@ -12082,8 +12082,17 @@ class IOSWebDriverClient extends WebDriverClient {
12082
12082
  });
12083
12083
  debugIOS(`Tapped at coordinates (${x}, ${y})`);
12084
12084
  } catch (error) {
12085
- debugIOS(`Failed to tap at (${x}, ${y}): ${error}`);
12086
- throw new Error(`Failed to tap at coordinates: ${error}`);
12085
+ debugIOS(`New tap endpoint failed, trying legacy endpoint: ${error}`);
12086
+ try {
12087
+ await this.makeRequest('POST', `/session/${this.sessionId}/wda/tap/0`, {
12088
+ x,
12089
+ y
12090
+ });
12091
+ debugIOS(`Tapped at coordinates (${x}, ${y}) using legacy endpoint`);
12092
+ } catch (fallbackError) {
12093
+ debugIOS(`Failed to tap at (${x}, ${y}): ${fallbackError}`);
12094
+ throw new Error(`Failed to tap at coordinates: ${fallbackError}`);
12095
+ }
12087
12096
  }
12088
12097
  }
12089
12098
  async swipe(fromX, fromY, toX, toY, duration = 500) {
@@ -12156,13 +12165,35 @@ class IOSWebDriverClient extends WebDriverClient {
12156
12165
  debugIOS(`Triple tapped at coordinates (${x}, ${y})`);
12157
12166
  }
12158
12167
  async getScreenScale() {
12159
- var _screenResponse_value;
12160
- const screenResponse = await this.makeRequest('GET', '/wda/screen');
12161
- if (null == screenResponse ? void 0 : null == (_screenResponse_value = screenResponse.value) ? void 0 : _screenResponse_value.scale) {
12162
- debugIOS(`Got screen scale from WDA screen endpoint: ${screenResponse.value.scale}`);
12163
- return screenResponse.value.scale;
12168
+ this.ensureSession();
12169
+ try {
12170
+ var _screenResponse_value;
12171
+ const screenResponse = await this.makeRequest('GET', `/session/${this.sessionId}/wda/screen`);
12172
+ if (null == screenResponse ? void 0 : null == (_screenResponse_value = screenResponse.value) ? void 0 : _screenResponse_value.scale) {
12173
+ debugIOS(`Got screen scale from WDA screen endpoint: ${screenResponse.value.scale}`);
12174
+ return screenResponse.value.scale;
12175
+ }
12176
+ } catch (error) {
12177
+ debugIOS(`Failed to get screen scale from /wda/screen: ${error}`);
12178
+ }
12179
+ try {
12180
+ debugIOS('Calculating screen scale from screenshot and window size');
12181
+ const [screenshotBase64, windowSize] = await Promise.all([
12182
+ this.takeScreenshot(),
12183
+ this.getWindowSize()
12184
+ ]);
12185
+ const { jimpFromBase64 } = await import("@midscene/shared/img");
12186
+ const screenshotImg = await jimpFromBase64(screenshotBase64);
12187
+ const screenshotWidth = screenshotImg.bitmap.width;
12188
+ const screenshotHeight = screenshotImg.bitmap.height;
12189
+ const scale = Math.max(screenshotWidth, screenshotHeight) / Math.max(windowSize.width, windowSize.height);
12190
+ const roundedScale = Math.round(scale);
12191
+ debugIOS(`Calculated screen scale: ${roundedScale} (screenshot: ${screenshotWidth}x${screenshotHeight}, window: ${windowSize.width}x${windowSize.height})`);
12192
+ return roundedScale;
12193
+ } catch (error) {
12194
+ debugIOS(`Failed to calculate screen scale: ${error}`);
12164
12195
  }
12165
- debugIOS('No screen scale found in WDA screen response');
12196
+ debugIOS('No screen scale found');
12166
12197
  return null;
12167
12198
  }
12168
12199
  async createSession(capabilities) {
@@ -12283,22 +12314,6 @@ class device_IOSDevice {
12283
12314
  defineActionKeyboardPress(async (param)=>{
12284
12315
  await this.pressKey(param.keyName);
12285
12316
  }),
12286
- defineAction({
12287
- name: 'IOSHomeButton',
12288
- description: 'Trigger the system "home" operation on iOS devices',
12289
- paramSchema: z.object({}),
12290
- call: async ()=>{
12291
- await this.home();
12292
- }
12293
- }),
12294
- defineAction({
12295
- name: 'IOSAppSwitcher',
12296
- description: 'Trigger the system "app switcher" operation on iOS devices',
12297
- paramSchema: z.object({}),
12298
- call: async ()=>{
12299
- await this.appSwitcher();
12300
- }
12301
- }),
12302
12317
  defineAction({
12303
12318
  name: 'IOSLongPress',
12304
12319
  description: 'Trigger a long press on the screen at specified coordinates on iOS devices',
@@ -12694,6 +12709,7 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
12694
12709
  async openUrlViaSafari(url) {
12695
12710
  try {
12696
12711
  debugDevice(`Opening URL via Safari: ${url}`);
12712
+ await this.wdaBackend.terminateApp('com.apple.mobilesafari');
12697
12713
  await this.wdaBackend.launchApp('com.apple.mobilesafari');
12698
12714
  await sleep(2000);
12699
12715
  await this.typeText(url);
@@ -12771,6 +12787,22 @@ const createPlatformActions = (device)=>({
12771
12787
  call: async (param)=>{
12772
12788
  await device.launch(param);
12773
12789
  }
12790
+ }),
12791
+ IOSHomeButton: defineAction({
12792
+ name: 'IOSHomeButton',
12793
+ description: 'Trigger the system "home" operation on iOS devices',
12794
+ paramSchema: z["void"]().describe('No parameters required'),
12795
+ call: async ()=>{
12796
+ await device.home();
12797
+ }
12798
+ }),
12799
+ IOSAppSwitcher: defineAction({
12800
+ name: 'IOSAppSwitcher',
12801
+ description: 'Trigger the system "app switcher" operation on iOS devices',
12802
+ paramSchema: z["void"]().describe('No parameters required'),
12803
+ call: async ()=>{
12804
+ await device.appSwitcher();
12805
+ }
12774
12806
  })
12775
12807
  });
12776
12808
  promisify(exec);
@@ -12787,10 +12819,16 @@ function agent_define_property(obj, key, value) {
12787
12819
  }
12788
12820
  getDebug('ios:agent');
12789
12821
  class IOSAgent extends Agent {
12822
+ createActionWrapper(name) {
12823
+ const action = this.wrapActionInActionSpace(name);
12824
+ return (...args)=>action(args[0]);
12825
+ }
12790
12826
  constructor(device, opts){
12791
- super(device, opts), agent_define_property(this, "launch", void 0), agent_define_property(this, "runWdaRequest", void 0);
12792
- this.launch = this.wrapActionInActionSpace('Launch');
12793
- this.runWdaRequest = this.wrapActionInActionSpace('RunWdaRequest');
12827
+ super(device, opts), agent_define_property(this, "launch", void 0), agent_define_property(this, "runWdaRequest", void 0), agent_define_property(this, "home", void 0), agent_define_property(this, "appSwitcher", void 0);
12828
+ this.launch = this.createActionWrapper('Launch');
12829
+ this.runWdaRequest = this.createActionWrapper('RunWdaRequest');
12830
+ this.home = this.createActionWrapper('IOSHomeButton');
12831
+ this.appSwitcher = this.createActionWrapper('IOSAppSwitcher');
12794
12832
  }
12795
12833
  }
12796
12834
  async function isPortAvailable(port) {
package/dist/es/index.mjs CHANGED
@@ -233,8 +233,17 @@ class IOSWebDriverClient extends WebDriverClient {
233
233
  });
234
234
  debugIOS(`Tapped at coordinates (${x}, ${y})`);
235
235
  } catch (error) {
236
- debugIOS(`Failed to tap at (${x}, ${y}): ${error}`);
237
- throw new Error(`Failed to tap at coordinates: ${error}`);
236
+ debugIOS(`New tap endpoint failed, trying legacy endpoint: ${error}`);
237
+ try {
238
+ await this.makeRequest('POST', `/session/${this.sessionId}/wda/tap/0`, {
239
+ x,
240
+ y
241
+ });
242
+ debugIOS(`Tapped at coordinates (${x}, ${y}) using legacy endpoint`);
243
+ } catch (fallbackError) {
244
+ debugIOS(`Failed to tap at (${x}, ${y}): ${fallbackError}`);
245
+ throw new Error(`Failed to tap at coordinates: ${fallbackError}`);
246
+ }
238
247
  }
239
248
  }
240
249
  async swipe(fromX, fromY, toX, toY, duration = 500) {
@@ -307,13 +316,35 @@ class IOSWebDriverClient extends WebDriverClient {
307
316
  debugIOS(`Triple tapped at coordinates (${x}, ${y})`);
308
317
  }
309
318
  async getScreenScale() {
310
- var _screenResponse_value;
311
- const screenResponse = await this.makeRequest('GET', '/wda/screen');
312
- if (null == screenResponse ? void 0 : null == (_screenResponse_value = screenResponse.value) ? void 0 : _screenResponse_value.scale) {
313
- debugIOS(`Got screen scale from WDA screen endpoint: ${screenResponse.value.scale}`);
314
- return screenResponse.value.scale;
319
+ this.ensureSession();
320
+ try {
321
+ var _screenResponse_value;
322
+ const screenResponse = await this.makeRequest('GET', `/session/${this.sessionId}/wda/screen`);
323
+ if (null == screenResponse ? void 0 : null == (_screenResponse_value = screenResponse.value) ? void 0 : _screenResponse_value.scale) {
324
+ debugIOS(`Got screen scale from WDA screen endpoint: ${screenResponse.value.scale}`);
325
+ return screenResponse.value.scale;
326
+ }
327
+ } catch (error) {
328
+ debugIOS(`Failed to get screen scale from /wda/screen: ${error}`);
315
329
  }
316
- debugIOS('No screen scale found in WDA screen response');
330
+ try {
331
+ debugIOS('Calculating screen scale from screenshot and window size');
332
+ const [screenshotBase64, windowSize] = await Promise.all([
333
+ this.takeScreenshot(),
334
+ this.getWindowSize()
335
+ ]);
336
+ const { jimpFromBase64 } = await import("@midscene/shared/img");
337
+ const screenshotImg = await jimpFromBase64(screenshotBase64);
338
+ const screenshotWidth = screenshotImg.bitmap.width;
339
+ const screenshotHeight = screenshotImg.bitmap.height;
340
+ const scale = Math.max(screenshotWidth, screenshotHeight) / Math.max(windowSize.width, windowSize.height);
341
+ const roundedScale = Math.round(scale);
342
+ debugIOS(`Calculated screen scale: ${roundedScale} (screenshot: ${screenshotWidth}x${screenshotHeight}, window: ${windowSize.width}x${windowSize.height})`);
343
+ return roundedScale;
344
+ } catch (error) {
345
+ debugIOS(`Failed to calculate screen scale: ${error}`);
346
+ }
347
+ debugIOS('No screen scale found');
317
348
  return null;
318
349
  }
319
350
  async createSession(capabilities) {
@@ -434,22 +465,6 @@ class IOSDevice {
434
465
  defineActionKeyboardPress(async (param)=>{
435
466
  await this.pressKey(param.keyName);
436
467
  }),
437
- defineAction({
438
- name: 'IOSHomeButton',
439
- description: 'Trigger the system "home" operation on iOS devices',
440
- paramSchema: z.object({}),
441
- call: async ()=>{
442
- await this.home();
443
- }
444
- }),
445
- defineAction({
446
- name: 'IOSAppSwitcher',
447
- description: 'Trigger the system "app switcher" operation on iOS devices',
448
- paramSchema: z.object({}),
449
- call: async ()=>{
450
- await this.appSwitcher();
451
- }
452
- }),
453
468
  defineAction({
454
469
  name: 'IOSLongPress',
455
470
  description: 'Trigger a long press on the screen at specified coordinates on iOS devices',
@@ -845,6 +860,7 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
845
860
  async openUrlViaSafari(url) {
846
861
  try {
847
862
  debugDevice(`Opening URL via Safari: ${url}`);
863
+ await this.wdaBackend.terminateApp('com.apple.mobilesafari');
848
864
  await this.wdaBackend.launchApp('com.apple.mobilesafari');
849
865
  await sleep(2000);
850
866
  await this.typeText(url);
@@ -922,6 +938,22 @@ const createPlatformActions = (device)=>({
922
938
  call: async (param)=>{
923
939
  await device.launch(param);
924
940
  }
941
+ }),
942
+ IOSHomeButton: defineAction({
943
+ name: 'IOSHomeButton',
944
+ description: 'Trigger the system "home" operation on iOS devices',
945
+ paramSchema: z["void"]().describe('No parameters required'),
946
+ call: async ()=>{
947
+ await device.home();
948
+ }
949
+ }),
950
+ IOSAppSwitcher: defineAction({
951
+ name: 'IOSAppSwitcher',
952
+ description: 'Trigger the system "app switcher" operation on iOS devices',
953
+ paramSchema: z["void"]().describe('No parameters required'),
954
+ call: async ()=>{
955
+ await device.appSwitcher();
956
+ }
925
957
  })
926
958
  });
927
959
  const execAsync = promisify(exec);
@@ -982,10 +1014,16 @@ function agent_define_property(obj, key, value) {
982
1014
  }
983
1015
  const debugAgent = getDebug('ios:agent');
984
1016
  class IOSAgent extends Agent {
1017
+ createActionWrapper(name) {
1018
+ const action = this.wrapActionInActionSpace(name);
1019
+ return (...args)=>action(args[0]);
1020
+ }
985
1021
  constructor(device, opts){
986
- super(device, opts), agent_define_property(this, "launch", void 0), agent_define_property(this, "runWdaRequest", void 0);
987
- this.launch = this.wrapActionInActionSpace('Launch');
988
- this.runWdaRequest = this.wrapActionInActionSpace('RunWdaRequest');
1022
+ super(device, opts), agent_define_property(this, "launch", void 0), agent_define_property(this, "runWdaRequest", void 0), agent_define_property(this, "home", void 0), agent_define_property(this, "appSwitcher", void 0);
1023
+ this.launch = this.createActionWrapper('Launch');
1024
+ this.runWdaRequest = this.createActionWrapper('RunWdaRequest');
1025
+ this.home = this.createActionWrapper('IOSHomeButton');
1026
+ this.appSwitcher = this.createActionWrapper('IOSAppSwitcher');
989
1027
  }
990
1028
  }
991
1029
  async function agentFromWebDriverAgent(opts) {
package/dist/lib/bin.js CHANGED
@@ -11421,6 +11421,12 @@ object-assign
11421
11421
  "use strict";
11422
11422
  module.exports = require("zlib");
11423
11423
  },
11424
+ "@midscene/shared/img": function(module) {
11425
+ "use strict";
11426
+ module.exports = import("@midscene/shared/img").then(function(module) {
11427
+ return module;
11428
+ });
11429
+ },
11424
11430
  open: function(module) {
11425
11431
  "use strict";
11426
11432
  module.exports = import("open").then(function(module) {
@@ -12220,8 +12226,17 @@ var __webpack_exports__ = {};
12220
12226
  });
12221
12227
  debugIOS(`Tapped at coordinates (${x}, ${y})`);
12222
12228
  } catch (error) {
12223
- debugIOS(`Failed to tap at (${x}, ${y}): ${error}`);
12224
- throw new Error(`Failed to tap at coordinates: ${error}`);
12229
+ debugIOS(`New tap endpoint failed, trying legacy endpoint: ${error}`);
12230
+ try {
12231
+ await this.makeRequest('POST', `/session/${this.sessionId}/wda/tap/0`, {
12232
+ x,
12233
+ y
12234
+ });
12235
+ debugIOS(`Tapped at coordinates (${x}, ${y}) using legacy endpoint`);
12236
+ } catch (fallbackError) {
12237
+ debugIOS(`Failed to tap at (${x}, ${y}): ${fallbackError}`);
12238
+ throw new Error(`Failed to tap at coordinates: ${fallbackError}`);
12239
+ }
12225
12240
  }
12226
12241
  }
12227
12242
  async swipe(fromX, fromY, toX, toY, duration = 500) {
@@ -12294,13 +12309,35 @@ var __webpack_exports__ = {};
12294
12309
  debugIOS(`Triple tapped at coordinates (${x}, ${y})`);
12295
12310
  }
12296
12311
  async getScreenScale() {
12297
- var _screenResponse_value;
12298
- const screenResponse = await this.makeRequest('GET', '/wda/screen');
12299
- if (null == screenResponse ? void 0 : null == (_screenResponse_value = screenResponse.value) ? void 0 : _screenResponse_value.scale) {
12300
- debugIOS(`Got screen scale from WDA screen endpoint: ${screenResponse.value.scale}`);
12301
- return screenResponse.value.scale;
12312
+ this.ensureSession();
12313
+ try {
12314
+ var _screenResponse_value;
12315
+ const screenResponse = await this.makeRequest('GET', `/session/${this.sessionId}/wda/screen`);
12316
+ if (null == screenResponse ? void 0 : null == (_screenResponse_value = screenResponse.value) ? void 0 : _screenResponse_value.scale) {
12317
+ debugIOS(`Got screen scale from WDA screen endpoint: ${screenResponse.value.scale}`);
12318
+ return screenResponse.value.scale;
12319
+ }
12320
+ } catch (error) {
12321
+ debugIOS(`Failed to get screen scale from /wda/screen: ${error}`);
12322
+ }
12323
+ try {
12324
+ debugIOS('Calculating screen scale from screenshot and window size');
12325
+ const [screenshotBase64, windowSize] = await Promise.all([
12326
+ this.takeScreenshot(),
12327
+ this.getWindowSize()
12328
+ ]);
12329
+ const { jimpFromBase64 } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@midscene/shared/img"));
12330
+ const screenshotImg = await jimpFromBase64(screenshotBase64);
12331
+ const screenshotWidth = screenshotImg.bitmap.width;
12332
+ const screenshotHeight = screenshotImg.bitmap.height;
12333
+ const scale = Math.max(screenshotWidth, screenshotHeight) / Math.max(windowSize.width, windowSize.height);
12334
+ const roundedScale = Math.round(scale);
12335
+ debugIOS(`Calculated screen scale: ${roundedScale} (screenshot: ${screenshotWidth}x${screenshotHeight}, window: ${windowSize.width}x${windowSize.height})`);
12336
+ return roundedScale;
12337
+ } catch (error) {
12338
+ debugIOS(`Failed to calculate screen scale: ${error}`);
12302
12339
  }
12303
- debugIOS('No screen scale found in WDA screen response');
12340
+ debugIOS('No screen scale found');
12304
12341
  return null;
12305
12342
  }
12306
12343
  async createSession(capabilities) {
@@ -12421,22 +12458,6 @@ var __webpack_exports__ = {};
12421
12458
  (0, device_namespaceObject.defineActionKeyboardPress)(async (param)=>{
12422
12459
  await this.pressKey(param.keyName);
12423
12460
  }),
12424
- (0, device_namespaceObject.defineAction)({
12425
- name: 'IOSHomeButton',
12426
- description: 'Trigger the system "home" operation on iOS devices',
12427
- paramSchema: core_namespaceObject.z.object({}),
12428
- call: async ()=>{
12429
- await this.home();
12430
- }
12431
- }),
12432
- (0, device_namespaceObject.defineAction)({
12433
- name: 'IOSAppSwitcher',
12434
- description: 'Trigger the system "app switcher" operation on iOS devices',
12435
- paramSchema: core_namespaceObject.z.object({}),
12436
- call: async ()=>{
12437
- await this.appSwitcher();
12438
- }
12439
- }),
12440
12461
  (0, device_namespaceObject.defineAction)({
12441
12462
  name: 'IOSLongPress',
12442
12463
  description: 'Trigger a long press on the screen at specified coordinates on iOS devices',
@@ -12832,6 +12853,7 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
12832
12853
  async openUrlViaSafari(url) {
12833
12854
  try {
12834
12855
  debugDevice(`Opening URL via Safari: ${url}`);
12856
+ await this.wdaBackend.terminateApp('com.apple.mobilesafari');
12835
12857
  await this.wdaBackend.launchApp('com.apple.mobilesafari');
12836
12858
  await (0, utils_namespaceObject.sleep)(2000);
12837
12859
  await this.typeText(url);
@@ -12909,6 +12931,22 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
12909
12931
  call: async (param)=>{
12910
12932
  await device.launch(param);
12911
12933
  }
12934
+ }),
12935
+ IOSHomeButton: (0, device_namespaceObject.defineAction)({
12936
+ name: 'IOSHomeButton',
12937
+ description: 'Trigger the system "home" operation on iOS devices',
12938
+ paramSchema: core_namespaceObject.z["void"]().describe('No parameters required'),
12939
+ call: async ()=>{
12940
+ await device.home();
12941
+ }
12942
+ }),
12943
+ IOSAppSwitcher: (0, device_namespaceObject.defineAction)({
12944
+ name: 'IOSAppSwitcher',
12945
+ description: 'Trigger the system "app switcher" operation on iOS devices',
12946
+ paramSchema: core_namespaceObject.z["void"]().describe('No parameters required'),
12947
+ call: async ()=>{
12948
+ await device.appSwitcher();
12949
+ }
12912
12950
  })
12913
12951
  });
12914
12952
  require("node:os");
@@ -12927,10 +12965,16 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
12927
12965
  }
12928
12966
  (0, logger_namespaceObject.getDebug)('ios:agent');
12929
12967
  class IOSAgent extends agent_namespaceObject.Agent {
12968
+ createActionWrapper(name) {
12969
+ const action = this.wrapActionInActionSpace(name);
12970
+ return (...args)=>action(args[0]);
12971
+ }
12930
12972
  constructor(device, opts){
12931
- super(device, opts), agent_define_property(this, "launch", void 0), agent_define_property(this, "runWdaRequest", void 0);
12932
- this.launch = this.wrapActionInActionSpace('Launch');
12933
- this.runWdaRequest = this.wrapActionInActionSpace('RunWdaRequest');
12973
+ super(device, opts), agent_define_property(this, "launch", void 0), agent_define_property(this, "runWdaRequest", void 0), agent_define_property(this, "home", void 0), agent_define_property(this, "appSwitcher", void 0);
12974
+ this.launch = this.createActionWrapper('Launch');
12975
+ this.runWdaRequest = this.createActionWrapper('RunWdaRequest');
12976
+ this.home = this.createActionWrapper('IOSHomeButton');
12977
+ this.appSwitcher = this.createActionWrapper('IOSAppSwitcher');
12934
12978
  }
12935
12979
  }
12936
12980
  async function isPortAvailable(port) {